全WA求解!!!

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

sunhaoxuan24 @ 2024-07-26 21:58:40

#include <iostream>
#include <cstring>
using namespace std;
string x[10][5]=
{
    "XXX",
    "X.X",
    "X.X",
    "X.X",
    "XXX",//0

    "..X",
    "..X",
    "..X",
    "..x",
    "..x",//1

    "XXX",
    "..X",
    "XXX",
    "X..",
    "XXX",//2

    "XXX",
    "..X",
    "XXX",
    "..X",
    "XXX",//3

    "X.X",
    "X.x",
    "XXX",
    "..X",
    "..x",//4

    "XXX",
    "X..",
    "XXX",
    "..X",
    "XXX",//5

    "XXX",
    "X..",
    "XXX",
    "X.X",
    "XXX",//6

    "XXX",
    "..X",
    "..X",
    "..X",
    "..X",//7

    "XXX",
    "X.X",
    "XXX",
    "X.X",
    "XXX",//8

    "XXX",
    "X.X",
    "XXX",
    "..X",
    "XXX",//9
};
int main()
{
    int n;
    char a[100];
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < n;j++)
        {
            if(a[j]=='0')
            {
                cout << x[0][i];
            }
            else if(a[j]=='1')
            {
                cout << x[1][i];
            }
            else if(a[j]=='2')
            {
                cout << x[2][i];
            }
            else if(a[j]=='3')
            {
                cout << x[3][i];
            }
            else if(a[j]=='4')
            {
                cout << x[4][i];
            }
            else if(a[j]=='5')
            {
                cout << x[5][i];
            }
            else if(a[j]=='6')
            {
                cout << x[6][i];
            }
            else if(a[j]=='7')
            {
                cout << x[7][i];
            }
            else if(a[j]=='8')
            {
                cout << x[8][i];
            }
            else if(a[j]=='9')
            {
                cout << x[9][i];
            }
            if(j<n-1)
            {
                cout << ".";
            }
        }
        cout << "\n";
    }
    return 0;
}

错误信息:Wrong Answer.wrong answer On line 2 column 11, read x, expected X.

求大佬帮解!!


by Aiden604 @ 2024-07-26 22:08:35

第4行,你这x数组定义的有问题


by Aiden604 @ 2024-07-26 22:14:17

你确实定义的是2维数组,但是范围太小了,你应该理解错了


by haimingbei @ 2024-07-26 22:16:45

@sunhaoxuan24 有一亿点长

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a[1005];
    cin>>n;
    for(int i=1;i<=n;i++)scanf("%1d",&a[i]);
    for(int i=1;i<=5;i++){
        for(int j=1;j<=n-1;j++){
            //0
            if(a[j]==0){
                if(i==1 || i==5)cout<<"XXX.";
                else if(i==2 || i==3 || i==4)cout<<"X.X.";
            }
            //1
            else if(a[j]==1)cout<<"..X.";
            //2
            else if(a[j]==2){
                if(i%2==1)cout<<"XXX.";
                else if(i==2)cout<<"..X.";
                else if(i==4)cout<<"X...";
            }
            //3
            else if(a[j]==3){
                if(i%2==1)cout<<"XXX.";
                else cout<<"..X.";
            }
            //4
            else if(a[j]==4){
                if(i==1 || i==2)cout<<"X.X.";
                else if(i==3)cout<<"XXX.";
                else if(i==4 || i==5)cout<<"..X.";
            }
            //5
            else if(a[j]==5){
                if(i%2==1)cout<<"XXX.";
                else if(i==2)cout<<"X...";
                else if(i==4)cout<<"..X.";
            }
            //6
            else if(a[j]==6){
                if(i%2==1)cout<<"XXX.";
                else if(i==2)cout<<"X...";
                else if(i==4)cout<<"X.X.";
            }
            //7
            else if(a[j]==7){
                if(i==1)cout<<"XXX.";
                else cout<<"..X.";
            }
            //8
            else if(a[j]==8){
                if(i%2==1)cout<<"XXX.";
                else cout<<"X.X.";
            }
            //9
            else if(a[j]==9){
                if(i%2==1)cout<<"XXX.";
                else if(i==2)cout<<"X.X.";
                else if(i==4)cout<<"..X.";
        }
    }
    //0
            if(a[n]==0){
                if(i==1 || i==5)cout<<"XXX";
                else if(i==2 || i==3 || i==4)cout<<"X.X";
            }
            //1
            else if(a[n]==1)cout<<"..X";
            //2
            else if(a[n]==2){
                if(i%2==1)cout<<"XXX";
                else if(i==2)cout<<"..X";
                else if(i==4)cout<<"X..";
            }
            //3
            else if(a[n]==3){
                if(i%2==1)cout<<"XXX";
                else cout<<"..X";
            }
            //4
            else if(a[n]==4){
                if(i==1 || i==2)cout<<"X.X";
                else if(i==3)cout<<"XXX";
                else if(i==4 || i==5)cout<<"..X";
            }
            //5
            else if(a[n]==5){
                if(i%2==1)cout<<"XXX";
                else if(i==2)cout<<"X..";
                else if(i==4)cout<<"..X";
            }
            //6
            else if(a[n]==6){
                if(i%2==1)cout<<"XXX";
                else if(i==2)cout<<"X..";
                else if(i==4)cout<<"X.X";
            }
            //7
            else if(a[n]==7){
                if(i==1)cout<<"XXX";
                else cout<<"..X";
            }
            //8
            else if(a[n]==8){
                if(i%2==1)cout<<"XXX";
                else cout<<"X.X";
            }
            //9
            else if(a[n]==9){
                if(i%2==1)cout<<"XXX";
                else if(i==2)cout<<"X.X";
                else if(i==4)cout<<"..X";
        }
        cout<<endl;
}
return 0;
}

by Aiden604 @ 2024-07-26 22:19:01

不对,你定义成了1维的数组


by Aiden604 @ 2024-07-26 22:34:07

???你有些数字咋是小写的?1和4有些X你都打成了小写的了


by Aiden604 @ 2024-07-26 22:37:09

@sunhaoxuan24 在2维数组x中,你有些字符"X"写成小写的了,怪不得全错


by Aiden604 @ 2024-07-26 22:41:30

还有一点,定义二维数组时,里面没加大括号,不加的话就是1维数组了,还有点优化, 具体看代码:

#include<bits/stdc++.h>
using namespace std;
string x[15][10]=
{
    {"XXX",
    "X.X",
    "X.X",
    "X.X",
    "XXX",},

    {"..X",
    "..X",
    "..X",
    "..X",
    "..X",},

    {"XXX",
    "..X",
    "XXX",
    "X..",
    "XXX",},

    {"XXX",
    "..X",
    "XXX",
    "..X",
    "XXX",},

    {"X.X",
    "X.X",
    "XXX",
    "..X",
    "..X",},

    {"XXX",
    "X..",
    "XXX",
    "..X",
    "XXX",},

    {"XXX",
    "X..",
    "XXX",
    "X.X",
    "XXX",},

    {"XXX",
    "..X",
    "..X",
    "..X",
    "..X",},

    {"XXX",
    "X.X",
    "XXX",
    "X.X",
    "XXX",},

    {"XXX",
    "X.X",
    "XXX",
    "..X",
    "XXX",},
};
int a[105];
int main()
{
    int n;
    cin >> n;
    for(int i=0; i < n; i++)
    {
        char t;
        cin>>t;
        a[i]=t-'0';
    }
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < n;j++)
        {
            cout<<x[a[j]][i];
            if(j<n-1)
            {
                cout <<".";
            }
        }
        cout << "\n";
    }
    return 0;
}

https://www.luogu.com.cn/record/168793484


by sunhaoxuan24 @ 2024-07-28 21:43:26

@Aiden604 谢谢,已关


by Aiden604 @ 2024-07-28 22:33:16

^_^


|