AK_lwh_888 @ 2024-07-23 20:28:11
#include<bits/stdc++.h>
using namespace std;
const int N=205;
int a[N][N]={0},n,x;
int main(){
scanf("%d",&n);
int i=1,ans=1,k=1;
while(cin>>x){
if(i%2==0){
for(int j=1;j<=x;++j){
if(ans>n)ans=1,k++;
a[k][ans]=1;
ans++;
}
}
else{
ans+=x;
if(ans>n){
ans=0+(ans-n);
k++;
}
}
i++;
}
for(int l=1;l<=n;++l){
for(int r=1;r<=n;++r){
cout<<a[l][r];
}
cout<<"\n";
}
return 0;
}
样例过了,只拿了60分,为什么
by LiujunjiaNC @ 2024-07-23 20:43:47
@KXGR ```cpp
using namespace std; const int N=205; int a[N][N]={0},n,x; int main(){ scanf("%d",&n); int i=1,ans=1,k=1; while(cin>>x){ if(i%2==0){ for(int j=1;j<=x;++j){ if(ans>n)ans=1,k++; a[k][ans]=1; ans++; } }else{ ans+=x; if(ans>n){ k+=ans/n; ans%=n;
}
}
i++;
}
for(int l=1;l<=n;++l){
for(int r=1;r<=n;++r){
cout<<a[l][r];
}
cout<<"\n";
}
return 0;
}
这道题可能有多行为零把```cpp
if(ans>n){
ans=0+(ans-n);
k++;
}
改为
if(ans>n){
k+=ans/n;
ans%=n;
}
by AK_lwh_888 @ 2024-07-23 20:44:37
@LiujunjiaNC 谢谢
by LiujunjiaNC @ 2024-07-23 20:45:09
#include<bits/stdc++.h>
using namespace std;
const int N=205;
int a[N][N]={0},n,x;
int main(){
scanf("%d",&n);
int i=1,ans=1,k=1;
while(cin>>x){
if(i%2==0){
for(int j=1;j<=x;++j){
if(ans>n)ans=1,k++;
a[k][ans]=1;
ans++;
}
}else{
ans+=x;
if(ans>n){
k+=ans/n;
ans%=n;
}
}
i++;
}
for(int l=1;l<=n;++l){
for(int r=1;r<=n;++r){
cout<<a[l][r];
}
cout<<"\n";
}
return 0;
}
出了一点问题
by jinky111 @ 2024-08-26 11:31:46
.