当前位置:网站首页>[Jiudu OJ 07] folding basket
[Jiudu OJ 07] folding basket
2022-07-06 05:37:00 【CodeLinghu】
【 Nine degrees OJ 07】 Folding basket
One 、 The question
Two 、 The answer process
Ideas :
First define a two-dimensional array , Then fill in characters from inside to outside , Finally, remove the four corners .
Note:
- The coordinates of the characters in the upper left corner of the middle are :
(n/2+1,n/2+1)
- The coordinates of the upper left corner of the secondary middle are :
(n/2+1-1,n/2+1-1)
#include<stdio.h>
int main(){
int outputbuf[82][82];// Output cache for pre typesetting
char a,b;// Two characters entered
int n;// Stack basket size
bool firstcase=true;// Whether it is the first group of data marks , The initial value is true
while(scanf("%d %c %c",&n,&a,&b)==3){
//scanf() The return value of the function is : Number of data items successfully assigned
if(firstcase==true){
// If the first set of data
firstcase=false;// Mark the first set of data as false
}
else printf("\n");
for(int i=1,j=1;i<=n;i+=2,j++){
// Output each circle from the inside out
int x=n/2+1,y=x;//
x-=j-1;y-=j-1;// Calculate the coordinates of the upper right corner of each circle
char c=j%2==1 ?a:b;// Calculate which character the current circle needs to use
for(int k=1;k<=i;k++){
// On the top of the current circle 、 Next 、 Left 、 Right assignment
outputbuf[x+k-1][y]=c;// Left assignment
outputbuf[x][y+k-1]=c;// Upper assignment
outputbuf[x+i-1][y+k-1]=c;// Right assignment
outputbuf[x+k-1][y+i-1]=c;// Lower assignment
}
}
if(n!=1){
// Set the four corners to empty
outputbuf[1][1]=' ';
outputbuf[n][1]=' ';
outputbuf[1][n]=' ';
outputbuf[n][n]=' ';
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
printf("%c",outputbuf[i][j]);
}
printf("\n");
}
}
}
边栏推荐
猜你喜欢
Sword finger offer II 039 Maximum rectangular area of histogram
Figure database ongdb release v-1.0.3
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Zoom and pan image in Photoshop 2022
Steady, 35K, byte business data analysis post
[Tang Laoshi] C -- encapsulation: classes and objects
用StopWatch 统计代码耗时
【OSPF 和 ISIS 在多路访问网络中对掩码的要求】
Using stopwatch to count code time
How to use PHP string query function
随机推荐
初识CDN
(column 22) typical column questions of C language: delete the specified letters in the string.
Web Security (V) what is a session? Why do I need a session?
Detailed summary of SQL injection
B站刘二大人-Softmx分类器及MNIST实现-Lecture 9
[SQL Server fast track] - authentication and establishment and management of user accounts
Vulhub vulnerability recurrence 73_ Webmin
剑指 Offer II 039. 直方图最大矩形面积
01. Project introduction of blog development project
ArcGIS application foundation 4 thematic map making
59. Spiral matrix
Modbus protocol communication exception
Check the useful photo lossless magnification software on Apple computer
Codeforces Round #804 (Div. 2) Editorial(A-B)
注释、接续、转义等符号
指针经典笔试题
Force buckle 1189 Maximum number of "balloons"
Fluent implements a loadingbutton with loading animation
What is independent IP and how about independent IP host?
Easy to understand I2C protocol