叠筐
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 12124 Accepted Submission(s): 3123
Problem Description
需要的时候,就把一个个大小差一圈的筐叠上去,使得从上往下看时,边筐花色交错。这个工作现在要让计算机来完成,得看你的了。
Input
输入是一个个的三元组,分别是,外筐尺寸n(n为满足0<n<80的奇整数),中心花色字符,外筐花色字符,后二者都为ASCII可见字符;
Output
输出叠在一起的筐图案,中心花色与外筐花色字符从内层起交错相叠,多筐相叠时,最外筐的角总是被打磨掉。叠筐与叠筐之间应有一行间隔。
Sample Input
11 B A 5 @ W
Sample Output
AAAAAAAAA ABBBBBBBBBA ABAAAAAAABA ABABBBBBABA ABABAAABABA ABABABABABA ABABAAABABA ABABBBBBABA ABAAAAAAABA ABBBBBBBBBA AAAAAAAAA @@@ @WWW@ @W@W@ @WWW@ @@@
这题必须要很细心而且要注意特殊数据,比如n=1时。
#include <stdio.h>
#define maxn 82
char map[maxn][maxn];
int main()
{
int n, i, j, k, sign, len, ii, cas = 1;
char ch[2];
while(scanf("%d %c %c", &n, &ch[0], &ch[1]) != EOF){
sign = ((n / 2) & 1);
for(i = 0; i < n / 2; ++i, sign = !sign){
len = n - i * 2;
k = len - 1; j = i;
while(k--) map[i][j++] = ch[sign];
k = len - 1; ii = i;
while(k--) map[ii++][j] = ch[sign];
k = len - 1;
while(k--) map[ii][j--] = ch[sign];
k = len - 1;
while(k--) map[ii--][j] = ch[sign];
}
map[n/2][n/2] = ch[0];
if(n != 1)
map[0][0] = map[0][n-1] = map[n-1][0] = map[n-1][n-1] = ' ';
if(cas++ != 1) printf("\n");
for(i = 0; i < n; ++i){
map[i][n] = '\0';
printf("%s\n", map[i]);
}
}
return 0;
}