我吐了...

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 MCH_Satrimiten @ 2021-10-06 16:06:23

@tangjiayang


by __K2FeO4 @ 2021-12-19 23:26:42

可以用Python编译器把它转化出来 最后不要忘记避开最后一个逗号

n='''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.'''
n=n.split('\n')
for i in range(0,40,4):
    for j in range(5):
        for k in range(3):
            print("'{}'".format(n[j][i+k]),end=',')
    print('')

直接有现成的

char a[10][5][3]={
'X','X','X','X','.','X','X','.','X','X','.','X','X','X','X',
'.','.','X','.','.','X','.','.','X','.','.','X','.','.','X',
'X','X','X','.','.','X','X','X','X','X','.','.','X','X','X',
'X','X','X','.','.','X','X','X','X','.','.','X','X','X','X',
'X','.','X','X','.','X','X','X','X','.','.','X','.','.','X',
'X','X','X','X','.','.','X','X','X','.','.','X','X','X','X',
'X','X','X','X','.','.','X','X','X','X','.','X','X','X','X',
'X','X','X','.','.','X','.','.','X','.','.','X','.','.','X',
'X','X','X','X','.','X','X','X','X','X','.','X','X','X','X',
'X','X','X','X','.','X','X','X','X','.','.','X','X','X','X'
}

上一页 |