Xing2721953052 @ 2022-11-13 14:36:57
#include <iostream>
using namespace std;
int main() {
int N, sum = 0;
cin >> N;
int a[205];
for (int i = 1; i <= 205; i++) {
cin >> a[i];
if (a[i] == 0) {
break;
}
if (i % 2 != 0 && a[i] != 0) {
for (int j = 1; j <= a[i]; j++) {
cout << "0";
sum++;
if (sum == N) {
cout << endl;
sum = 0;
}
}
} else if (i % 2 == 0 && a[i] != 0) {
for (int k = 1; k <= a[i]; k++) {
cout << "1";
sum++;
if (sum == N) {
cout << endl;
sum = 0;
}
}
}
}
return 0;
}
by HUFT @ 2022-11-13 14:50:10
题目里没有说遇到零就停,把
if (a[i] == 0) {
break;
}
删掉 把循环改成:
while(cin >> a[i]){
.....
i++;
}
您的0和1输出反了