求助,示例一样,全wa,呜呜呜

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

hell17o @ 2023-07-29 16:37:34

#include<iostream>
using namespace std;

char res[10][400];
char tmp[5][30]=
{
    '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',
};
int main()
{
    int n;
    cin>>n;
    char num[110];
    int i=0;
    int count=0;
    while(n--)
    {
        int x;
        scanf("%1d",&x);//一长串数字只会存入一个,接下来一个个处理
        int a=0,b=0;
        //作为答案数组的下标标记
        switch (x)
        {
            case 0:a=0,b=2;break;
            case 1:a=3,b=5;break;
            case 2:a=6,b=8;break;
            case 3:a=9,b=11;break;
            case 4:a=12,b=14;break;
            case 5:a=15,b=17;break;
            case 6:a=18,b=20;break;
            case 7:a=21,b=23;break;
            case 8:a=24,b=26;break;
            case 9:a=27,b=29;break;
        }
        for(int i=0;i<5;i++)//总共五行
        {
            for(int j=a;j<=b;j++)
            {
                res[i][count++]=tmp[i][j];
            }
            count=count-2;
        }
        count=count+3;
        if(n!=0)
        {
            for(int i=0;i<5;i++)
            res[i][count]='.';
        }
        count++;
    }

    for(int i=0;i<5;i++)
    {
        for(int j=0;j<=count;j++)
        cout<<res[i][j];

        cout<<endl; 
    }
    system("pause");
    return 0;   
}

by hell17o @ 2023-07-29 16:38:28

太长了,跟我在编译器上的有点出入


by hell17o @ 2023-07-29 16:41:20

请大佬们复制粘贴到编译器上


by liyifan0804 @ 2023-07-31 15:54:17

我没太理解你的思路,不过你可以看一下我的代码↓↓↓

#include<iostream>
#include<math.h>
using namespace std;
int n;
char shuchu[101];
int main(){
    cin>>n>>shuchu;
    for(int j=0;j<=n-1;j++){
        if(shuchu[j]-48==0||shuchu[j]-48==2||shuchu[j]-48==3||shuchu[j]-48==5||shuchu[j]-48==6||shuchu[j]-48==7||shuchu[j]-48==8||shuchu[j]-48==9){
            cout<<"XXX";
        }
        else if(shuchu[j]-48==1){
            cout<<"..X";
        }
        else if(shuchu[j]-48==4){
            cout<<"X.X";
        }
        if(j<n-1){
        cout<<".";
        }
        else{
        cout<<endl;
        }
    }
    for(int j=0;j<=n-1;j++){
        if(shuchu[j]-48==1||shuchu[j]-48==2||shuchu[j]-48==3||shuchu[j]-48==7){
            cout<<"..X";
        }
        else if(shuchu[j]-48==0||shuchu[j]-48==4||shuchu[j]-48==8||shuchu[j]-48==9){
            cout<<"X.X";
        }
        else if(shuchu[j]-48==5||shuchu[j]-48==6){
            cout<<"X..";
        }
        if(j<n-1){
        cout<<".";
        }
        else{
        cout<<endl;
        }
    }
    for(int j=0;j<=n-1;j++){
        if(shuchu[j]-48==2||shuchu[j]-48==3||shuchu[j]-48==4||shuchu[j]-48==5||shuchu[j]-48==6||shuchu[j]-48==8||shuchu[j]-48==9){
            cout<<"XXX";
        }
        else if(shuchu[j]-48==0){
            cout<<"X.X";
        }
        else if(shuchu[j]-48==1||shuchu[j]-48==7){
            cout<<"..X";
        }
        if(j<n-1){
        cout<<".";
        }
        else{
        cout<<endl;
        }
    }
    for(int j=0;j<=n-1;j++){
        if(shuchu[j]-48==1||shuchu[j]-48==3||shuchu[j]-48==4||shuchu[j]-48==5||shuchu[j]-48==7||shuchu[j]-48==9){
            cout<<"..X";
        }
        else if(shuchu[j]-48==0||shuchu[j]-48==6||shuchu[j]-48==8){
            cout<<"X.X";
        }
        else if(shuchu[j]-48==2){
            cout<<"X..";
        }
        if(j<n-1){
        cout<<".";
        }
        else{
        cout<<endl;
        }
    }
    for(int j=0;j<=n-1;j++){
        if(shuchu[j]-48==0||shuchu[j]-48==2||shuchu[j]-48==3||shuchu[j]-48==5||shuchu[j]-48==6||shuchu[j]-48==8||shuchu[j]-48==9){
            cout<<"XXX";
        }
        else if(shuchu[j]-48==1||shuchu[j]-48==4||shuchu[j]-48==7){
            cout<<"..X";
        }
        if(j<n-1){
        cout<<".";
        }
    }
}

|