Red_Cow @ 2023-11-05 18:12:35
#include<stdio.h>
int main()
{
int i,n,N
int flag=0;//控制0,1转换
int count=0;//计数控制换行
int sum=0;
scanf("%d",&N);
while(sum!=N*N)
{
//printf("a");
scanf("%d",&n);
sum+=n;
if(flag==0)
for(i=1;i<=n;i++)
{
printf("0");
flag=1;
count++;
if(count%N==0) printf("\n");
}
else if(flag==1)
for(i=1;i<=n;i++)
{
//sleep(1);
printf("1");
flag=0;
count++;
if(count%N==0) printf("\n");
}
}
return 0;
}
by Parrhesiates @ 2023-11-05 18:24:41
可能会有0,如果有0的话,你这样写,就不翻了
by Parrhesiates @ 2023-11-05 18:25:13
@Red_Cow 你可以把翻转写在循环下面
by GTAH2333 @ 2023-11-05 18:33:14
这应该是可以过的呀
by GTAH2333 @ 2023-11-05 18:34:08
好吧,收回我的话
by GTAH2333 @ 2023-11-05 18:38:47
如 liuyidu 所说
if(flag==0){
flag=1;
for(i=1; i<=n; i++) {
printf("0");
count++;
if(count%N==0) printf("\n");
}
}else if(flag==1){
flag=0;
for(i=1; i<=n; i++) {
printf("1");
count++;
if(count%N==0) printf("\n");
}
}
by Red_Cow @ 2023-11-07 16:42:31
@liuyidu 恍然大悟,感谢解答
by Red_Cow @ 2023-11-07 16:43:13
@GTAH2333 ok谢谢
by GTAH2333 @ 2023-11-07 19:22:21
不客气