leave_for @ 2023-10-11 22:19:21
下载的测试点数据检查后也是正常的
#include<iostream>
using namespace std;
int main()
{
short n=0;
short temp=0;
short mtrx[20000];
short loop=0;
cin>>n;
while(temp<n*n)
{
cin>>mtrx[loop];
temp+=mtrx[loop];
loop++;
}
temp=0;
loop=1;
for(short i=0;loop<n;i++)
{
for(short j=0;j<mtrx[i];j++)
{
if(temp==n) {cout<<endl;temp=0;loop++;}
cout<<i%2;
temp++;
}
}
return 0;
}
WA测试点数据:\ in:
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
out:
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
00000000000000000000000000000000000011110000000000000000000000000000000000000000
怎么回事啊,有没有人来解答一下
by zhouzihang3 @ 2023-10-11 23:05:47
你这个代码很奇怪,也不知道是不是因为习惯不一样……你要压行你就认真压,能不能不要只压那一行if(temp==n) {cout<<endl;temp=0;loop++;}
啊喂(
然后就是输入,我个人建议在输入时制表 (因为我的代码就是这么干的) ,这样比较省脑细胞。这里把mtrx
数组改成一个变量,然后从头开始按照题干赋值。
while(m<n*n){
cin>>x;//你的mtrx
if(y==1){//y存储下一次输入要赋值的量
for(int i=m;i<m+x;i++){
a[i]=1;//答案这里为了方便应该存一维
}
y=0;
}else{
y=1;
}
m+=x;//更改m值
}
接下来输出,使用一个新变量k
记录答案数组遍历到的位置,然后两层循环输出
int k=0;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<a[k];
k++;
}
cout<<endl;
}
我给你一些建议:
1.变量名要么照题干写,要么使用英文单词,所有变量只用于一个用途,除非你有万全把握
2.我建议(可采取可不采取)能用变量就 撅 不用数组,因为这些用完就丢,还浪费内存
ok,答疑完毕,睡觉
41行,最长的讨论区
by sbno333 @ 2023-10-11 23:15:27
改代码就要用最少的改动获得正确
#include<iostream>
using namespace std;
int main()
{
short n=0;
short temp=0;
short mtrx[20000];
short loop=0;
cin>>n;
while(temp<n*n)
{
cin>>mtrx[loop];
temp+=mtrx[loop];
loop++;
}
temp=0;
loop=1;
for(short i=0;loop<=n;i++)//此处用<=而不是=
{
//cout<<mtrx[i]<<endl;
for(short j=0;j<mtrx[i];j++)
{
if(temp==n) {cout<<endl;temp=0;loop++;}
cout<<i%2;
temp++;
}
if(temp==n){cout<<endl;temp=0;loop++;}//最大的问题,程序执行到最后temp=n,loop=n时已经该完了,如果不特判后头就不会判断了,因此死循环
}
return 0;
}
``` @[zero_egg](/user/615166)
@[leave_for](/user/1093564)
by zhouzihang3 @ 2023-10-11 23:16:25
@sbno333 好钓
by zhouzihang3 @ 2023-10-11 23:17:24
@sbno333 Markdown贴错了害得我找了两秒半@
在哪
by sbno333 @ 2023-10-11 23:17:48
6