theBeatles @ 2023-09-07 12:37:32
#include<bits/stdc++.h>
using namespace std;
int g[300][300];
int main()
{
int N,num = 0;
cin >> N;
int count;
bool flag = true;//true表示0,false表示1
while(cin >> count){
for(int i = 1;i <= count;i++){
if(flag){
g[num / 7][num % 7] = 0;
}else{
g[num / 7][num % 7] = 1;
}
num++;
}
flag = !flag;
}
for(int i = 0;i < N;i++){
for(int j = 0;j < N;j++){
cout << g[i][j];
}
cout << endl;
}
}
by theBeatles @ 2023-09-07 12:45:45
我又改写了一下,感觉思路一样,但是对了,之前用二维数组储存的方法确实太傻了
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N,num = 0;
cin >> N;
int g[N * N + 10];
int count,j = 0;
int flag = 0;
while(cin >> count){
for(int i = 1;i <= count;i++){
g[j++] = flag;
}
flag = !flag;
}
for(int i = 0;i < j;i++){
cout << g[i];
if((i + 1) % N == 0){
cout << endl;
}
}
return 0;
}
by xuchuhan @ 2023-09-07 13:27:34
@theBeatles 改你的第一份代码。
g[num / 7][num % 7] = 0;
变成g[num / N][num % N] = 0;
g[num / 7][num % 7] = 1;
变成g[num / N][num % N] = 1;
by theBeatles @ 2023-09-07 14:14:51
@xuchuhan 啊啊啊啊啊谢谢大佬!!!我晕了,怎么检查也没检查出来┭┮﹏┭┮