#include
#include
void main()
{
int N,a,b;
int i,i2,i3,last,middle,middle1;
char dna[30][100];
scanf("%d",&N);
for (i=0;i
{
scanf("%d%d",&a,&b);
middle=a/2+1;
middle1=middle-1;
for (i2=1;i2<=a-1;i2++)
{
last=a+1-i2;
if (i2<=middle)
{
for (i3=1;i3<=last;i3++)
{
if (i3==i2||i3==last)
dna[i2-1][i3-1]='X';
else
dna[i2-1][i3-1]=' ';
if (i3==last)
dna[i2-1][i3]='\0';
}
}
else
strcpy(dna[i2-1],dna[--middle1]);
}
for (i2=1;i2<=b;i2++)
{
for (i3=0;i3
printf("%s\n",dna[i3]);
}
printf("%s\n\n",dna[0]);
}
}
解题思路:
先把 X X 储存在一个二维数组中,然后根据b重复度重复打印这个,打印完后在把再X X补上(两个换行符)
X
注意事项:
数组下标不能乱。
参考代码: