OMG 全是wa wa wa

P5730 【深基5.例10】显示屏

thw123huaL @ 2021-01-05 12:47:51

好奇怪 每个数字之间的间隔也注意到了

就是wa wa wa

#include<iostream>
#include<cstdio>
using namespace std;

void oput(int j, int a) ;    //输出不同数值、不同行的相应字符串

int main(){
    int N;
    scanf("%d",&N); //N个数字
    int a[N];
    char ch[N+1];
    for(int i = 0; i <= N; i++)
        ch[i] = getchar();  //保存为字符串,下转为int数字
    for(int i = 0; i < N; i++)
        a[i] = int(ch[i+1]-48 );    //转为数字

    bool first = 1; //判断是否为第一个数字,否则加入分隔点
    for(int j = 0; j < 5; j++){//行遍历
        if(j == 0){//第一行
            for(int i = 0; i < N; i++){
                if(!first){
                    printf(".");    //不是第一,分隔
                    oput(j,a[i]);
                }
                else {
                    first = 0;  //第一,不加分隔
                    oput(j,a[i]);
                }
            }
            first = 1;
            cout<<endl;
        }
        else if(j == 1){    //第二行
            for(int i =0; i < N; i++){
                if(!first){
                    printf(".");
                    oput(j,a[i]);
                }
                else{
                    first = 0;
                    oput(j,a[i]);
                }
            }
            first = 1;
            cout<<endl;
        }
        else if(j == 2){    //第三行
            for(int i =0; i < N; i++){
                if(!first){
                    printf(".");
                    oput(j,a[i]);
                }
                else{
                    first = 0;
                    oput(j,a[i]);
                }
            }
            first = 1;
            cout<<endl;
        }
        else if(j == 3){    //第四行
            for(int i =0; i < N; i++){
                if(!first){
                    printf(".");
                    oput(j,a[i]);
                }
                else{
                    first = 0;
                    oput(j,a[i]);
                }
            }
            first = 1;
            cout<<endl;
        }
        else if(j == 4){    //第五行
            for(int i =0; i < N; i++){
                if(!first){
                    printf(".");
                    oput(j,a[i]);
                }
                else{
                    first = 0;
                    oput(j,a[i]);
                }
            }
            first = 1;
            cout<<endl;
        }
    }
    return 0;
}
void oput(int j, int a) {
    if(j == 0){         //第一行各数字的输出情况
        if(a == 0) cout<<"XXX";
        else if(a == 1) cout<<"..X";
        else if(a == 2) cout<<"XXX";
        else if(a == 3) cout<<"XXX";
        else if(a == 4) cout<<"X.X";
        else if(a == 5) cout<<"XXX";
        else if(a == 6) cout<<"XXX";
        else if(a == 7) cout<<"XXX";
        else if(a == 8) cout<<"XXX";
        else if(a == 9) cout<<"XXX";

    }
    else if(j == 1){
        if(a == 0) cout<<"X.X";
        else if(a == 1) cout<<"..X";
        else if(a == 2) cout<<"..X";
        else if(a == 3) cout<<"..X";
        else if(a == 4) cout<<"X.X";
        else if(a == 5) cout<<"X..";
        else if(a == 6) cout<<"X..";
        else if(a == 7) cout<<"..X";
        else if(a == 8) cout<<"X.X";
        else if(a == 9) cout<<"X.X";
    }
    else if(j == 2){
        if(a == 0) cout<<"X.X";
        else if(a == 1) cout<<"..X";
        else if(a == 2) cout<<"XXX";
        else if(a == 3) cout<<"XXX";
        else if(a == 4) cout<<"XXX";
        else if(a == 5) cout<<"XXX";
        else if(a == 6) cout<<"XXX";
        else if(a == 7) cout<<"..X";
        else if(a == 8) cout<<"XXX";
        else if(a == 9) cout<<"XXX";
    }
    else if(j == 3){
        if(a == 0) cout<<"X.X";
        else if(a == 1) cout<<"..X";
        else if(a == 2) cout<<"X..";
        else if(a == 3) cout<<"..X";
        else if(a == 4) cout<<"..X";
        else if(a == 5) cout<<"..X";
        else if(a == 6) cout<<"X.X";
        else if(a == 7) cout<<"..X";
        else if(a == 8) cout<<"X.X";
        else if(a == 9) cout<<"..X";
    }
    else if(j == 4){
        if(a == 0) cout<<"XXX";
        else if(a == 1) cout<<"..X";
        else if(a == 2) cout<<"XXX";
        else if(a == 3) cout<<"XXX";
        else if(a == 4) cout<<"..X";
        else if(a == 5) cout<<"XXX";
        else if(a == 6) cout<<"XXX";
        else if(a == 7) cout<<"..X";
        else if(a == 8) cout<<"XXX";
        else if(a == 9) cout<<"XXX";
    }

}

求求dalao们了


by thw123huaL @ 2021-01-05 12:56:31

下载测试数据了

..X...X.X.X.XXX...X.X.X

..X...X.X.X.X.....X.X.X

..X...X.XXX.XXX...X.XXX

..X...X...X...X...X...X

..X...X...X.XXX...X...X

上面是下载的测试数据,下面是输出数据

数了一下,好像也一样 呜呜呜

..X...X.X.X.XXX...X.X.X

..X...X.X.X.X.....X.X.X

..X...X.XXX.XXX...X.XXX

..X...X...X...X...X...X

..X...X...X.XXX...X...X


by justinjia @ 2021-01-15 15:03:24

@thw123huaL 洛谷IDE亲测,结果不一样:

(那个11451是我临时加的输出)

还是用scanf("%s",/*与%s配合时可以不加&*/ch);读入数据吧,要不然那么多换行符、空字符的问题我也无法解决。。。


|