全RE,C++,求调

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

znzryb @ 2024-08-06 09:55:48

本地clion试了好几组数据好像都行,不知道为什么提交洛谷RE了,求调,愿意帮我调的我一定关注。

#include <cstdio>
#include <string>
// 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
using namespace std;
int n;int number[110];char a;
string first_row[10]={"XXX","..X","XXX","XXX","X.X","XXX","XXX","XXX","XXX","XXX"};
string secon_row[10]={"X.X","..X","..X","..X","X.X","X..","X..","..X","X.X","X.X"};
string third_row[10]={"X.X","..X","XXX","XXX","XXX","XXX","XXX","..X","XXX","XXX"};
string forth_row[10]={"X.X","..X","X..","..X","..X","..X","X.X","..X","X.X","..X"};
string fifth_row[10]={"XXX","..X","XXX","XXX","..X","XXX","XXX","..X","XXX","XXX"};
int main()
{

    scanf("%d",&n);
    getchar();
    for(int i=0;i<n;i++) {
        a=getchar();        // 这样会读到换行符
        int value=a-'0';
        number[i]=value;          //static_cast<int>(a)-static_cast<int>('0');
    }
    for (int i=0;i<5;i++) {
        for(int j=0;j<n;j++) {
            if(i==0) {
                int num=number[j];
                if (j==n-1) {
                    printf("%s",first_row[num].c_str());
                }else {
                    printf("%s.",first_row[num].c_str());
                }
            }else if(i==1) {
                int num=number[j];
                if (j==n-1) {
                    printf("%s",secon_row[num].c_str());
                }else {
                    printf("%s.",secon_row[num].c_str());
                }
            } else if(i==2) {
                int num=number[j];
                if (j==n-1) {
                    printf("%s",third_row[num].c_str());
                }else {
                    printf("%s.",third_row[num].c_str());
                }
            }else if(i==3) {
                int num=number[j];
                if (j==n-1) {
                    printf("%s",forth_row[num].c_str());
                }else {
                    printf("%s.",forth_row[num].c_str());
                }
            } else if(i==4) {
                int num=number[j];
                if (j==n-1) {
                    printf("%s",fifth_row[num].c_str());
                }else {
                    printf("%s.",fifth_row[num].c_str());
                }
            }
        }
        printf("\n");
    }
    return 0;
}

by znzryb @ 2024-08-06 09:58:42

测试数据下下来在本地也成功输出了,还是看不出什么问题


by YJL2013 @ 2024-08-06 10:20:22

是不是吧语言改成自动识别了,改成c++20试试。


by red369 @ 2024-08-06 19:22:34

第一,所有数组最好多开5个大小
第二,非必要不用getchar()
AC代码:

#include<bits/stdc++.h>
// 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
using namespace std;
int n;
string number;
string row1[11]={"XXX","..X","XXX","XXX","X.X","XXX","XXX","XXX","XXX","XXX"};
string row2[11]={"X.X","..X","..X","..X","X.X","X..","X..","..X","X.X","X.X"};
string row3[11]={"X.X","..X","XXX","XXX","XXX","XXX","XXX","..X","XXX","XXX"};
string row4[11]={"X.X","..X","X..","..X","..X","..X","X.X","..X","X.X","..X"};
string row5[11]={"XXX","..X","XXX","XXX","..X","XXX","XXX","..X","XXX","XXX"};
int main()
{
    cin>>n>>number;
    for(int i=0;i<n-1;i++)cout<<row1[number[i]-'0']<<'.';cout<<row1[number[n-1]-'0'];
    cout<<endl;
    for(int i=0;i<n-1;i++)cout<<row2[number[i]-'0']<<'.';cout<<row2[number[n-1]-'0'];
    cout<<endl;
    for(int i=0;i<n-1;i++)cout<<row3[number[i]-'0']<<'.';cout<<row3[number[n-1]-'0'];
    cout<<endl;
    for(int i=0;i<n-1;i++)cout<<row4[number[i]-'0']<<'.';cout<<row4[number[n-1]-'0'];
    cout<<endl;
    for(int i=0;i<n-1;i++)cout<<row5[number[i]-'0']<<'.';cout<<row5[number[n-1]-'0'];
    cout<<endl;

    return 0;
}

by red369 @ 2024-08-06 19:25:19

@znzryb


by znzryb @ 2024-08-06 22:43:23

@red369 我绰,谢谢你们


by znzryb @ 2024-08-06 22:45:19

@red369 谢谢你,我以后会注意的。这个代码我之后也改了改,输入输出改成cin cout以后就好了。


by red369 @ 2024-08-08 16:09:57

@znzryb cin cout 不重要,数组开小了


by znzryb @ 2024-08-08 16:14:39

@red369 好的,谢谢,已关注


|