WA了

P1319 压缩技术

x12345678901 @ 2024-03-15 18:34:59

``` #include<iostream> #include<cmath> #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<string> #include<cstdlib> #include<vector> //#defide cfor(i,a,b) for(int i=(a);i<(b);i++) using namespace std; int main(){ int n; cin>>n; int c; bool b=false; int l=0; while((c=getchar())!='\n'){ int in=c-'0'; //cout<<b; for(int i=0;i<in;i++){ cout<<b; if(++l==n){ cout<<endl; l=0; } } b=!b; //cout<<b; } return 0; } ``` 输出全是一

by canwen @ 2024-04-05 14:28:32

我这么写AC的

#include<iostream>
using namespace std;
int shuzu[201*201];
int main(){
    int n,a,flag=0,j=0;
    cin>>n;
    while(scanf("%d",&a)==1){
        flag++;
        //奇数的情况 :0
        if(flag%2==1){
            for(int i=1;i<=a;i++){
                shuzu[++j]=0;
            }
        }else{
            //偶数的情况:1 
            for(int i=1;i<=a;i++){
                shuzu[++j]=1;
            }

        }

    }
    for(int i=1;i<=j;i++){
        cout<<shuzu[i];
        if(i%n==0) cout<<endl;
    }

    return 0;
}

|