TD21260225 @ 2022-09-21 20:57:38
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
int num,temp=0;
int arr[100];
int N ,W;
cin>>N>>W;
int array[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if(num== W){
num=0;
cin>>W;
if(temp==1){
temp=0;
}else{
temp =1;
}
}
array[i][j]=temp;
num++;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cout <<array[i][j];
}
cout << endl;
}
}
by TD21260225 @ 2022-09-21 20:58:12
输出是
7 3 1 6 1 6 4 3 1 6 1 6 1 3 7
0001000
0001000
0001111
0001000
0001000
0001000
1111111
by fortyyearslater @ 2022-09-21 21:13:44
@TD21260225 num没赋初值0
by Mr_RedStone @ 2022-09-21 21:14:21
你把那个array[N][N]改成[210][210],就能过了,因为数组定义时传长度得是const类型
by LeTu_Jun @ 2022-09-21 21:27:17
@TD21260225 不要在定义数组时用变量定义大小,这是一个 UB
by liwenxi114514 @ 2022-09-21 21:33:41
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
int num=0,temp=0;
int arr[100];
int N ,W;
cin>>N>>W;
int array[210][210];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if(num== W){
num=0;
cin>>W;
if(temp==1){
temp=0;
}else{
temp =1;
}
}
array[i][j]=temp;
num++;
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cout <<array[i][j];
}
cout << endl;
}
}
by TD21260225 @ 2022-09-22 14:31:35
@liwenxi110720 谢谢啊
by TD21260225 @ 2022-09-22 14:31:55
@LeTu_Jun 谢谢
by TD21260225 @ 2022-09-22 14:32:14
@Mr_RedStone 谢谢
by TD21260225 @ 2022-09-22 14:32:45
@fortyyearslater 谢谢