我吐了...

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

ttkuilei @ 2021-10-06 15:07:54

打了好久代码,但所有数它都输出

XXX
X.X
XXX
..X
XXX

WA \times 4 + RE \times 1

#include<iostream>
#include<string>
using namespace std;
int main() {
    int n,x=0;
    string str;
    char a[6][400];
    cin>>n>>str;
    for(int i=1;i<=n;i++) {
        int k=4*i-3;
        switch(str[i-1]) {
            case'0':a[1][k]=a[1][k+1]=a[1][k+2]=a[2][k]=a[2][k+2]=a[3][k]=a[3][k+2]=a[4][k]=a[4][k+2]=a[5][k]=a[5][k+1]=a[5][k+2]='X';
                    a[2][k+1]=a[3][k+1]=a[4][k+1]='.';
            case'1':a[1][k+2]=a[2][k+2]=a[5][k+2]=a[3][k+2]=a[4][k+2]='X';
                    a[1][k]=a[2][k]=a[2][k+1]=a[3][k]=a[3][k+1]=a[4][k]=a[4][k+1]=a[5][k]=a[5][k+1]=a[1][k+1]='.';
            case'2':a[1][k+1]=a[1][k+2]=a[1][k]=a[2][k+2]=a[3][k]=a[3][k+2]=a[3][k+1]=a[4][k]=a[5][k]=a[5][k+1]=a[5][k+2]='X';
                    a[2][k]=a[2][k+1]=a[4][k+1]=a[4][k+2]='.';
            case'3':a[1][k+1]=a[1][k+2]=a[1][k]=a[2][k+2]=a[3][k]=a[3][k+2]=a[3][k+1]=a[4][k+2]=a[5][k]=a[5][k+1]=a[5][k+2]='X';
                    a[2][k]=a[2][k+1]=a[4][k+1]=a[4][k]='.';
            case'4':a[1][k+2]=a[1][k]=a[2][k+2]=a[2][k]=a[3][k+2]=a[3][k+1]=a[3][k]=a[4][k+2]=a[5][k+2]='X';
                    a[1][k+1]=a[4][k]=a[2][k+1]=a[4][k+1]=a[5][k]=a[5][k+1]='.';
            case'5':a[1][k+1]=a[1][k+2]=a[1][k]=a[2][k]=a[3][k]=a[3][k+2]=a[3][k+1]=a[4][k+2]=a[5][k]=a[5][k+1]=a[5][k+2]='X';
                    a[2][k+2]=a[2][k+1]=a[4][k+1]=a[4][k]='.';
            case'6':a[1][k+1]=a[1][k+2]=a[1][k]=a[2][k]=a[4][k]=a[3][k]=a[3][k+2]=a[3][k+1]=a[4][k+2]=a[5][k]=a[5][k+1]=a[5][k+2]='X';
                    a[2][k+2]=a[2][k+1]=a[4][k+1]='.';
            case'7':a[1][k]=a[1][k+2]=a[2][k+2]=a[5][k+2]=a[3][k+2]=a[1][k+1]=a[4][k+2]='X';
                    a[2][k]=a[2][k+1]=a[3][k]=a[3][k+1]=a[4][k]=a[4][k+1]=a[5][k]=a[5][k+1]='.';
            case'8':a[1][k+1]=a[2][k+2]=a[1][k+2]=a[1][k]=a[2][k]=a[4][k]=a[3][k]=a[3][k+2]=a[3][k+1]=a[4][k+2]=a[5][k]=a[5][k+1]=a[5][k+2]='X';
                    a[2][k+1]=a[4][k+1]='.';
            case'9':a[1][k+1]=a[2][k+2]=a[1][k+2]=a[1][k]=a[2][k]=a[3][k]=a[3][k+2]=a[3][k+1]=a[4][k+2]=a[5][k]=a[5][k+1]=a[5][k+2]='X';
                    a[2][k+1]=a[4][k]=a[4][k+1]='.';
        }
        a[1][k+3]=a[2][k+3]=a[3][k+3]=a[4][k+3]=a[5][k+3]='.';
    }
    for(int i=1;i<=5;i++) {for(int j=1;j<4*n;j++) cout<<a[i][j]; cout<<endl;}
    return 0;
}

switch 语句错了吗?? 求挑错!!

有点乱,大佬们忍一下。。

最后一个RE我也不知道怎么回事。。


by HYdroKomide @ 2021-10-06 15:12:43

@tangjiayang 直接把所有要显示出来的数存在数组里不香吗?


by HYdroKomide @ 2021-10-06 15:13:18

@tangjiayang 然后直接输出数组


by MCH_Satrimiten @ 2021-10-06 15:14:58

@tangjiayang 您每次都存在一个地方啊?


by ttkuilei @ 2021-10-06 15:15:21

@Kevin_FOS 我就是这么编的代码。。。


by ttkuilei @ 2021-10-06 15:16:27

@MCH_Satrimiten

int k=4*i-3;

by ttkuilei @ 2021-10-06 15:16:58

心态崩了


by HYdroKomide @ 2021-10-06 15:42:38

@tangjiayang 不,我的意思是:

const string a[5][10]={"XXX","..X","XXX","XXX","X.X","XXX","XXX","XXX","XXX","XXX",
                       "X.X","..X","..X","..X","X.X","X..","X..","..X","X.X","X.X",
                       "X.X","..X","XXX","XXX","XXX","XXX","XXX","..X","XXX","XXX",
                       "X.X","..X","X..","..X","..X","..X","X.X","..X","X.X","..X",
                       "XXX","..X","XXX","XXX","..X","XXX","XXX","..X","XXX","XXX"};

by HYdroKomide @ 2021-10-06 15:43:00

@tangjiayang 这样存下来


by MCH_Satrimiten @ 2021-10-06 16:05:37

#include<bits/stdc++.h>
using namespace std;
string a0[10]={{"XXX"},{"X.X"},{"X.X"},{"X.X"},{"XXX"}};
string a1[10]={{"..X"},{"..X"},{"..X"},{"..X"},{"..X"}};
string a2[10]={{"XXX"},{"..X"},{"XXX"},{"X.."},{"XXX"}};
string a3[10]={{"XXX"},{"..X"},{"XXX"},{"..X"},{"XXX"}};
string a4[10]={{"X.X"},{"X.X"},{"XXX"},{"..X"},{"..X"}};
string a5[10]={{"XXX"},{"X.."},{"XXX"},{"..X"},{"XXX"}};
string a6[10]={{"XXX"},{"X.."},{"XXX"},{"X.X"},{"XXX"}};
string a7[10]={{"XXX"},{"..X"},{"..X"},{"..X"},{"..X"}};
string a8[10]={{"XXX"},{"X.X"},{"XXX"},{"X.X"},{"XXX"}};
string a9[10]={{"XXX"},{"X.X"},{"XXX"},{"..X"},{"XXX"}};
string f[6][1000];
int main() {
    int n,x=0;
    string str;
    cin>>n>>str;
    int a=0,b=0,c=0,d=0,e=0;
    for(int i=1;i<=n;i++) {
        if(str[i-1]=='0')f[1][++a]=a0[0],f[2][++b]=a0[1],f[3][++c]=a0[2],f[4][++d]=a0[3],f[5][++e]=a0[4];
        if(str[i-1]=='1')f[1][++a]=a1[0],f[2][++b]=a1[1],f[3][++c]=a1[2],f[4][++d]=a1[3],f[5][++e]=a1[4];
        if(str[i-1]=='2')f[1][++a]=a2[0],f[2][++b]=a2[1],f[3][++c]=a2[2],f[4][++d]=a2[3],f[5][++e]=a2[4];
        if(str[i-1]=='3')f[1][++a]=a3[0],f[2][++b]=a3[1],f[3][++c]=a3[2],f[4][++d]=a3[3],f[5][++e]=a3[4];
        if(str[i-1]=='4')f[1][++a]=a4[0],f[2][++b]=a4[1],f[3][++c]=a4[2],f[4][++d]=a4[3],f[5][++e]=a4[4];
        if(str[i-1]=='5')f[1][++a]=a5[0],f[2][++b]=a5[1],f[3][++c]=a5[2],f[4][++d]=a5[3],f[5][++e]=a5[4];
        if(str[i-1]=='6')f[1][++a]=a6[0],f[2][++b]=a6[1],f[3][++c]=a6[2],f[4][++d]=a6[3],f[5][++e]=a6[4];
        if(str[i-1]=='7')f[1][++a]=a7[0],f[2][++b]=a7[1],f[3][++c]=a7[2],f[4][++d]=a7[3],f[5][++e]=a7[4];
        if(str[i-1]=='8')f[1][++a]=a8[0],f[2][++b]=a8[1],f[3][++c]=a8[2],f[4][++d]=a8[3],f[5][++e]=a8[4];
        if(str[i-1]=='9')f[1][++a]=a9[0],f[2][++b]=a9[1],f[3][++c]=a9[2],f[4][++d]=a9[3],f[5][++e]=a9[4];
    }
//    cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;
    for(int j=1;j<=a;j++){
        if(j==a){cout<<f[1][j];break;}
        cout<<f[1][j]<<".";
    }cout<<endl;
    for(int j=1;j<=b;j++){
        if(j==b){cout<<f[2][j];break;}
        cout<<f[2][j]<<".";
    }cout<<endl;
    for(int j=1;j<=c;j++){
        if(j==c){cout<<f[3][j];break;}
        cout<<f[3][j]<<".";
    }cout<<endl;
    for(int j=1;j<=d;j++){
        if(j==d){cout<<f[4][j];break;}
        cout<<f[4][j]<<".";
    }cout<<endl;
    for(int j=1;j<=e;j++){
        if(j==e){cout<<f[5][j];break;}
        cout<<f[5][j]<<".";
    }
    return 0;
}

by MCH_Satrimiten @ 2021-10-06 16:06:04

终于TM写出来了


| 下一页