输出跟测试点一样但显示too long

P1319 压缩技术

trosky @ 2021-05-12 16:43:17

#include<iostream>
using namespace std;
int n,a,i=0,sum=0,hh=0;
int main()
{
    cin>>n;
    while(hh<n*n)
    {
        cin>>a;
        ++i;
        if(i%2!=0)
        {
            for(int j=1;j<=a;++j)
            {
                cout<<"0";
                sum++;
                if(sum==n)
                {
                    cout<<endl;
                    sum=0;
                }
            }
        }
        else
        {
            for(int j=1;j<=a;++j)
            {
                cout<<"1";
                sum++;
                if(sum==n)
                {
                    sum=0;
                    cout<<endl;
                }
            }
        }
        hh++;
    }
    return 0;
}

by Gary88 @ 2021-05-12 22:03:53

你输入太多了,不一定有n*n个输入,应该是总和是n*n


by Gary88 @ 2021-05-12 22:05:14

@trosky 只需要把

hh++;

改为

hh+=a;

即可通过本题


by trosky @ 2021-05-13 17:15:29

@Gary88 谢谢


by Gary88 @ 2021-05-13 19:53:40

@trosky 不用谢


|