求助!能过样例却爆零!

P1319 压缩技术

shiroko2008 @ 2021-10-04 14:28:24

#include<iostream>
using namespace std;
int x(int a) {
    return (a>0?0:1);
}
int main()
{
    int n;
    cin>>n;
    bool flag=false;
    int a[100]{0},f=0,t=0,pointer=0,p=0;
    while (t<n*n) {
        cin>>a[pointer];
        t+=a[pointer++];
    }
    t=0;
    pointer=0;
    while (t<n*n) {
        for (int j=0;j<a[pointer];j++) {
            cout<<flag;
            p++;
            if (p==7) {
                cout<<endl;
                p=0;
            }
        }
        pointer++;
        t++;
        flag=x(flag);
    }
    return 0;
}

by wyw666 @ 2021-10-04 14:35:28

if (p==7) {

你应该把 7 改成 n。

另外,过样例跟拿不拿到分没关系啊喂(


by 离城梦_dream @ 2021-10-05 20:57:22

@bugwriter n不是永远等于7,只不过是样例中n是7,所以7要改成n


by maojinbo1979 @ 2021-11-12 17:07:56

@离城梦_dream 一语点醒梦中人。


|