那几个测试数据都一样,但是都是显示WA

P1319 压缩技术

apengya @ 2021-11-16 16:36:52

#include<iostream>
using namespace std;
int main()
{
    int n,c=0,a,b=0,d,e,f=0;
    cin >> n;
    for (int i = 1; b<=n*n ; i++)
    {
        cin >> a;
        c++;
        d = c % 2;

        for (int j = 1; j <= a; j++)
        {
            f++;
            e = f % n;
            if (d == 1) cout << 0;
            else cout << 1;
            if (e == 0) cout << endl;
        }
        b = a + b;
    }
    return 0;
}

by LHQing @ 2021-11-16 16:39:05

@apengya

In Line 7:

b<n*n


by LHQing @ 2021-11-16 16:40:13

@apengya b=n*n时其实已经输出完了


by apengya @ 2021-11-16 16:45:08

@LHQing 谢谢大佬 大佬,我能再问问您他们说的那个模拟算法是啥意思或者从哪学么;


by LHQing @ 2021-11-16 16:47:47

@apengya 是一种思想,就是按照题目的要求照着写.

另外:比如说这题,你可以先把他存在一个一维数组上(不用考虑换行).然后再n次n个输出.


by apengya @ 2021-11-16 16:49:47

@LHQing 哦哦哦,大体了解了


|