福到了
Description
“福”字倒着贴,寓意“福到”。不论到底算不算民俗,本题且请你编写程序,把各种汉字倒过来输出。这里要处理的每个汉字是由一个 N×N 的网格组成的,网格中的元素或者为字符@
或者为空格。而倒过来的汉字所用的字符由裁判指定。
Input
输入在第一行中给出倒过来的汉字所用的字符、以及网格的规模正整数N (1 \le N \le 1001≤N≤100),其间以 1 个空格分隔;随后 N 行,每行给出 N 个字符,或者为@
或者为空格。
Output
输出倒置的网格,如样例所示。但是,如果这个字正过来倒过去是一样的,就先输出bu yong dao le
,然后再用输入指定的字符将其输出。
Sample Input 1
$ 9 @ @@@@@ @@@ @@@ @ @ @ @@@ @@@ @@@ @@@@@ @@@ @ @ @ @@@ @@@@@ @ @ @ @ @ @@@@@
Sample Output 1
$$$$$ $ $ $ $ $ $$$$$ $$$ $ $ $ $$$ $$$$$ $$$ $$$ $$$ $ $ $ $$$ $$$ $$$$$ $
Sample Input 2
& 3 @@@ @ @@@
Sample Output 2
bu yong dao le &&& & &&&
Source
PTA
#include <stdio.h>
#include <string.h>
int main()
{
int n,i,j,k=0;
char c;
scanf("%c%d",&c,&n);
getchar();
char a[101][101];
for(i=0;i<n;i++)
{
gets(a[i]);
}
int m;
if(n%2==0) m=n/2;
else m=(n-1)/2;
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=a[n-i-1][n-j-1])
{
k=1;
break;
}
}
}
if(k==0) printf("bu yong dao le\n");
for(i=n-1;i>=0;i--)
{
for(j=n-1;j>=0;j--)
{
if(a[i][j]=='@') printf("%c",c);
else printf(" ");
}
if(i!=0) printf("\n");
}
}