小白求助,为什么前4个测试点全wa,最后一个过了

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

laoguo1112359 @ 2023-05-27 17:18:19

#include <bits/stdc++.h>
using namespace std;
char ch[100];
char sum[5][400];
int i;
int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",ch);
    char* s = ch;
    while(*s != '\0')
    {
        switch(*s)
        {
            case '0':
                sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
                sum[1][i]=sum[1][i+2]='X';sum[1][i+1]='.';
                sum[2][i]=sum[2][i+2]='X';sum[2][i+1]='.';
                sum[3][i]=sum[3][i+2]='X';sum[3][i+1]='.';
                sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
                break;
            case '1':
                sum[0][i]=sum[0][i+1]='.';sum[0][i+2]='X';
                sum[1][i]=sum[1][i+1]='.';sum[1][i+2]='X';
                sum[2][i]=sum[2][i+1]='.';sum[2][i+2]='X';
                sum[3][i]=sum[3][i+1]='.';sum[3][i+2]='X';
                sum[4][i]=sum[4][i+1]='.';sum[4][i+2]='X';
                break;
            case '2':
                sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
                sum[1][i]=sum[1][i+1]='.';sum[1][i+2]='X';
                sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
                sum[3][i]='X';sum[3][i+1]=sum[3][i+2]='.';
                sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
                break;
            case '3':
                sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
                sum[1][i]=sum[1][i+1]='.';sum[1][i+2]='X';
                sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
                sum[3][i]=sum[3][i+1]='.';sum[3][i+2]='X';
                sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
                break;
            case '4':
                sum[0][i]=sum[0][i+2]='X';sum[0][i+1]='.';
                sum[1][i]=sum[1][i+2]='X';sum[1][i+1]='.';
                sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
                sum[3][i]=sum[3][i+1]='.';sum[3][i+2]='X';
                sum[4][i]=sum[4][i+1]='.';sum[4][i+2]='X';
                break;
            case '5':
                sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
                sum[1][i]=sum[1][i+1]='X';sum[1][i+2]='.';
                sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
                sum[3][i]='.';sum[3][i+1]=sum[3][i+2]='X';
                sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
                break;
            case '6':
                sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
                sum[1][i]=sum[1][i+1]='X';sum[1][i+2]='.';
                sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
                sum[3][i]=sum[3][i+2]='X';sum[3][i+1]='.';
                sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
                break;
            case '7':
                sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
                sum[1][i]=sum[1][i+1]='.';sum[1][i+2]='X';
                sum[2][i]=sum[2][i+1]='.';sum[2][i+2]='X';
                sum[3][i]=sum[3][i+1]='.';sum[3][i+2]='X';
                sum[4][i]=sum[4][i+1]='.';sum[4][i+2]='X';
                break;
            case '8':
                sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
                sum[1][i]=sum[1][i+2]='X';sum[1][i+1]='.';
                sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
                sum[3][i]=sum[3][i+2]='X';sum[3][i+1]='.';
                sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
                break;
            case '9':
                sum[0][i]=sum[0][i+1]=sum[0][i+2]='X';
                sum[1][i]=sum[1][i+2]='X';sum[1][i+1]='.';
                sum[2][i]=sum[2][i+1]=sum[2][i+2]='X';
                sum[3][i]='.';sum[3][i+1]=sum[3][i+2]='X';
                sum[4][i]=sum[4][i+1]=sum[4][i+2]='X';
                break;  
        }
        if(*(s+1)!='\0')
        {
            sum[0][i+3]=sum[1][i+3]=sum[2][i+3]=sum[3][i+3]=sum[4][i+3]='.';

        }
        i+=4;
        s++;
    }
    for(int j=0;j<5;j++)
    {
        for(int k=0;k<4*n;k++)
            cout<<sum[j][k];
        cout<<endl;
    }

    return 0;
}

/*
0     1     2     3     4     5     6     7     8     9
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 SCAR_L @ 2023-05-28 08:44:38

@laoguo1112359 要不然运行的时候会输出一些奇怪的东西(最后一列):

(我用的是luogu的在线IDE)


上一页 |