Freakk @ 2023-12-12 10:11:19
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
int cnt_zero,cnt_one,cnt=0;
while(cin>>cnt_zero>>cnt_one){
for(int i = 0;i < cnt_zero;i++){
cnt++;
cout<<"0";
if(cnt == n){
cout<<endl;
cnt = 0;
}
}
for(int i = 0;i < cnt_one;i++){
cnt++;
cout<<"1";
if(cnt == n){
cout<<endl;
cnt = 0;
}
}
}
return 0;
}
by thliup @ 2023-12-12 21:59:10
@Freakk 我想问这个while循环怎么停止呢
by Freakk @ 2023-12-13 14:10:56
@thliup 我没有考虑退出循环的问题,如果要退出循环的话就加一个变量统计数字个数是否等于N*N
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
int sum = 0;
int cnt_zero,cnt_one,cnt=0;
while(cin>>cnt_zero>>cnt_one){
for(int i = 0;i < cnt_zero;i++){
sum++;
cnt++;
cout<<"0";
if(cnt == n){
cout<<endl;
cnt = 0;
}
}
for(int i = 0;i < cnt_one;i++){
sum++;
cnt++;
cout<<"1";
if(cnt == n){
cout<<endl;
cnt = 0;
}
}
if(sum == n*n) break;
}
return 0;
}
然后我就发现了每次必须输入接下来的0和1的数量才能打印一遍,也就导致了某一次输入0的数量后就达到了N*N就不会打印了,就像下面这个
输入
80 0 10 360 4 211 2 400 2 12 10 16 2 78 2 78 2 78 2 18 2 23 11 24 2 78 2 78 2 78 2 78 2 78 2 28 2 48 2 72 2 78 2 78 2 78 2 516 2 400 2 93 4 40 10 575 2 400 2 38 2 78 2 78 2 78 2 18 2 58 2 78 2 78 2 78 2 78 2 78 2 28 2 48 2 72 2 78 2 78 2 78 2 28 43 445 2 400 2 93 4 40
输出
11111111110000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000111100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000001100000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000011000000000000111111111100000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000001100000000000000000000000111111111110000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000110000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000001100000000000000000
00000000000000000000000000000000000000000000000000000000000001100000000000000000
00000000000000000000000000000000000000000000000000000000000001100000000000000000
00000000000000000000000000000000000000000000000000000000000001100000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000001100000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000011000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000011110000000000000000000000000000000000000000
11111111110000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000001100000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000011000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000001100000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000000000001100000000000
00000000000000000110000000000000000000000000000000000000000000000001100000000000
00000000000000000000000000000000000000000000000000000000000001100000000000000000
00000000000000000000000000000000000000000000000000000000000001100000000000000000
00000000000000000000000000000000000000000000000000000000000001100000000000000000
00000000000000000000000000000000000000000000000000000000000001100000000000000000
00000000000111111111111111111111111111111111111111111100000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000001100000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000011000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000001111
可以看的出来最后的40个0没有打印