这代码输出完为什么不会结束?

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0,x,i,sum=0;
    bool flag=false;
    cin >> n;
    while(cnt<n*n)
    {
        cin >> x;
        for(i=1;i<=x;i++)
        {
            ++sum;
            if(sum>n)
            {
                cout << endl;
                sum=1;
            }
            if(flag)
            {
                cout << 1;
            }
            else
            {
                cout << 0;
            }
        }
        flag=!flag;
    }
    return 0;
}

输出完以后这代码就不会停止

你的cnt一直为0,n也没有变化过,while的循环条件也没有变化过,所以循环条件的值一直为true,死循环了

img

cnt你忘记加值嘞吧,死循环