放大的X
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7295 Accepted Submission(s): 2157
如3*3的’X’应如下所示:
X X
X
X X
5*5的’X’如下所示:
X X
X X
X
X X
X X
接下来有T行,每行有一个正奇数n(3 <= n <= 79),表示放大的规格。
#include<stdio.h>
int main()
{
int m,n,i,j;
scanf("%d",&m);
while(m--)
{
scanf("%d",&n);
for(i=1;i<=(n+1)/2;i++)
for(j=1;j<=n+1-i;j++)
{
if((i==j)||(n+1==i+j))
printf("X");
else printf(" ");
if(j==n+1-i) printf("
");
}
for(i=(n+1)/2+1;i<n+1;i++)
for(j=n;j>=n+1-i;j--)
{
if((i==j)||(n+1==i+j))
printf("X");
else printf(" ");
if(j==n+1-i) printf("
");
}
printf("
");
}
return 0;
}
方法2;
#include<stdio.h>
int main()
{
int m,n,i,j;
scanf("%d",&m);
while(m--)
{
scanf("%d",&n);
for(i=0;i<=(n-1)/2;i++)
for(j=0;j<=n-1-i;j++)
{
if((i==j)||(n-1==i+j))
printf("X");
else printf(" ");
if(j==n-1-i) printf("
");
}
for(i=(n-1)/2+1;i<=n-1;i++)
for(j=n-1;j>=n-1-i;j--)
{
if((i==j)||(n-1==i+j))
printf("X");
else printf(" ");
if(j==n-1-i) printf("
");
}
printf("
");
}
return 0;
}