tjer @ 2022-01-30 10:40:50
#include<bits/stdc++.h>
#define maxn 1000005
using namespace std;
int n,zero,one,n1;
int main () {
cin >>n;
for(int i=1;i<=n;i++){
cin >>zero >>one;
for(int j=1;j<=zero;j++){
cout <<"0";
n1++;
if(n1%n==0) cout <<endl;
}
for(int j=1;j<=one;j++){
cout <<"1";
n1++;
if(n1%n==0) cout <<endl;
}
}
return 0;
}
by Wiene @ 2022-01-30 11:56:59
@cjiajiayyds 您无法保证一定会有n次的0/1交替
by Wiene @ 2022-01-30 11:57:54
可能会有更多,也可能会少
by Wiene @ 2022-01-30 11:59:45
@cjiajiayyds 可以用
while(cin>>x){
}
来读入,在循环体里判断当前是0/1并输出
by tjer @ 2022-01-30 12:02:13
#include<bits/stdc++.h>
#define maxn 1000005
using namespace std;
int n,a,n1,flag=1;
int main () {
cin >>n;
while(cin >>a){
if(flag){
for(int j=1;j<=a;j++){
cout <<"0";
n1++;
if(n1%n==0) cout <<endl;
}
flag=!flag;
}else{
for(int j=1;j<=a;j++){
cout <<"1";
n1++;
if(n1%n==0) cout <<endl;
}
flag=!flag;
}
}
return 0;
}
by tjer @ 2022-01-30 12:06:34
谢谢dalao @AC_duckling