大佬们来看看,结果和下载的样例一样,为啥全都WA了

P1319 压缩技术

hhhdddfff @ 2020-07-24 15:24:46

#include<iostream>
#include<string>

using namespace std;

int before,row,after,n,num,rest=0,sum=0,flag=0;

int main()
{
    cin >> n;
    while (sum <= n*n)
    {
        cin >> num;
        sum += num;
        rest += num;
        if (rest >= n)
        {
            before = rest%n;
            row = rest / n;
            after = n - rest + num;
            if (flag == 0)
            {
                string str1(after, '0');
                cout << str1 << endl;
                for (int i = 1; i < n; i++)
                {
                    string str(n, '0');
                }
                string str2(before, '0');
                cout << str2;
            }
            else if (flag == 1)
            {
                string str1(after, '1');
                cout << str1 << endl;
                for (int i = 1; i < n; i++)
                {
                    string str(n, '1');
                }
                string str2(before, '1');
                cout << str2;
            }
            rest = before;
            flag = 1 - flag;
        }
        else
        {
            if (flag == 0)
            {
                string str(num, '0');
                cout << str;
            }
            else if (flag == 1)
            {
                string str(num, '1');
                cout << str;
            }
            flag = 1 - flag;
        }
    }
    return 0;
}

by 高逸飞 @ 2020-07-24 15:32:46

UB?


by nbxh2008 @ 2020-07-31 10:57:13

我也一样呀!


|