测试正常,评测爆0

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

ethan01 @ 2020-04-21 22:18:55

#include<stdio.h>
int main()
{
    int num;
    int i,t;
    char number[103];
    char pic[10][6][4]={"   ",
                        "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"};
    scanf("%d",&num);
    for (i = 0;i <= num;i++){
        scanf("%c",&number[i]);
    }
    for (i = 1;i <= num;i++){
        t = number[i] - '0';
        printf("%c%c%c",pic[t][1][0],pic[t][1][1],pic[t][1][2]);
        if(i < num){
            printf(".");
        }
        else{
            printf("\n");
        }
    }
    for (i = 1;i <= num;i++){
        t = number[i] - '0';
        printf("%c%c%c",pic[t][2][0],pic[t][2][1],pic[t][2][2]);
        if(i < num){
            printf(".");
        }
        else{
            printf("\n");
        }
    }
    for (i = 1;i <= num;i++){
        t = number[i] - '0';
        printf("%c%c%c",pic[t][3][0],pic[t][3][1],pic[t][3][2]);
        if(i < num){
            printf(".");
        }
        else{
            printf("\n");
        }
    }
    for (i = 1;i <= num;i++){
        t = number[i] - '0';
        printf("%c%c%c",pic[t][4][0],pic[t][4][1],pic[t][4][2]);
        if(i < num){
            printf(".");
        }
        else{
            printf("\n");
        }
    }
    for (i = 1;i <= num;i++){
        t = number[i] - '0';
        printf("%c%c%c",pic[t][5][0],pic[t][5][1],pic[t][5][2]);
        if(i < num){
            printf(".");
        }
    }
    return 0;
}

by ethan01 @ 2020-04-21 22:19:33

如题,萌新暴风哭泣,求解答


by Trinitrotoluene @ 2020-04-21 22:22:08

@ethan01 '/n' 被宁吃了?


by ethan01 @ 2020-04-22 08:44:20

@Trinitrotoluene 哪个\n,能不能说详细一点鸭


by Trinitrotoluene @ 2020-04-22 09:38:02

@ethan01 所有的 '/n' 都被 "scanf("%c")" 读进去了


by ethan01 @ 2020-04-22 10:08:28

@Trinitrotoluene 我还是不太明白。我觉得第一个数字之后的\n被存到number[0]里面了,右面的调用是从number[1]开始的,这样不是相当于屏蔽掉了回车的影响了吗


by Trinitrotoluene @ 2020-04-22 10:37:00

@ethan01 你用 "scanf("%s")" 吧,要不然用 cin 算了


by ethan01 @ 2020-04-22 11:34:44

@Trinitrotoluene 用%s肯定能过,我就是想不明白%c的那个错在哪里了


by Trinitrotoluene @ 2020-04-22 11:48:14

@ethan01 数据换行有时 '/n' 有时 '/r/n',你要是不确定的话就到 IDE 上试试


by Trinitrotoluene @ 2020-04-22 11:48:30

你的代码我在 IDE 上运行了1分钟都没有输出答案


|