输出出来0和1的位置完全相反咋办

P1319 压缩技术

orangeSteve_dev @ 2024-07-18 00:35:04

#include <bits/stdc++.h>
using namespace std;
int n,x,y,k;
int main() {
    cin>>n;
    int ans=n*n;
    x=n;
    while(ans) {
        cin>>y;
        ans-=y;
        k++;
        for(int i=1; i<=y; i++) {
            x--;
            cout<<k%2;
            if(x==0) {
                printf("\n",x=n);
            }
        }
    }
    return 0;
}

by Misophiliac @ 2024-07-18 00:45:19

@yangmu_dev 绷,相反就调整过来啊

cout<<k%2;\tocout<<1-k%2;


by ToMaT @ 2024-07-18 08:14:39

#include <bits/stdc++.h>
using namespace std;
int n,x,y,k;
int main() {
    cin>>n;
    int ans=n*n;
    x=n;
    while(ans) {
        cin>>y;
        ans-=y;
        k++;
        for(int i=1; i<=y; i++) {
            x--;
            cout<<(!(k%2));
            if(x==0) {
                printf("\n",x=n);
            }
        }
    }
    return 0;
}

取反一下


by ToMaT @ 2024-07-18 08:16:34

@yangmu_dev


by orangeSteve_dev @ 2024-07-19 22:49:49

@ToMaT 谢谢大佬


|