Zlc晨鑫 @ 2020-03-15 13:59:10
编译选项:gcc main.c -o main
#include <stdio.h>
int main() {
int n, a;
scanf("%d", &n);
int f = 0, cnt = 0;
while (scanf("%d", &a)) {
for (int i = 0; i < a; i++) {
printf("%d", f);
cnt++;
if (cnt == n) {
cnt = 0;
putchar('\n');
}
}
f = !f;
}
return 0;
}
求助大佬。
by Zlc晨鑫 @ 2020-03-15 13:59:42
似乎是读入的锅
by Zlc晨鑫 @ 2020-03-15 14:00:19
by 老八小憨包 @ 2020-03-15 14:01:41
by Aw顿顿 @ 2020-03-15 14:04:17
$\text{怎么读入啊}^\text{怎么读入啊}_\text{怎么读入啊}$
by 老八小憨包 @ 2020-03-15 14:05:20
写成:
while(scanf("%d",&a)!=EOF)
亲测可过
by 老八小憨包 @ 2020-03-15 14:06:04
@Zlc晨鑫
by mazihang2022 @ 2020-03-15 14:09:41
@Zlc晨鑫
while(~scanf("%d",&a))
by flysong @ 2020-03-15 14:13:04
@Zlc晨鑫 scanf在读不到数据是不会返回0或false,而是返回-1。
by 血色黄昏 @ 2020-03-15 14:32:43
一般while条件为输入时都用cin比较好(我们老师)
by Zlc晨鑫 @ 2020-03-15 14:36:30
@老八小憨包 @mazihang2022 @flysong
谢谢大佬们