c语言全WA求助

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

xi_inluogu @ 2023-11-14 16:33:13

#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[100];
    for(int i = 0;i < n;i++)
    {
        int x;
        scanf("%d",&x);
        a[i] = x;
    }
    for(int i = 0;i < n;i++)
    {
        int x = a[i];
        switch(x)
        {
            case 0:
            printf("XXX");
            break;
            case 1:
            printf("..X");
            break;
            case 2:
            printf("XXX");
            break;
            case 3:
            printf("XXX");
            break;
            case 4:
            printf("X.X");
            break;
            case 5:
            printf("XXX");
            break;
            case 6:
            printf("XXX");
            break;
            case 7:
            printf("XXX");
            break;
            case 8:
            printf("XXX");
            break;
            case 9:
            printf("XXX");
            break;
        }
        if(i < n-1) printf(".");
    }
    printf("\n");
    for(int i = 0;i < n;i++)
    {
        int x = a[i];
        switch(x)
        {
            case 0:
            printf("X.X");
            break;
            case 1:
            printf("..X");
            break;
            case 2:
            printf("..X");
            break;
            case 3:
            printf("..X");
            break;
            case 4:
            printf("X.X");
            break;
            case 5:
            printf("X..");
            break;
            case 6:
            printf("X..");
            break;
            case 7:
            printf("..X");
            break;
            case 8:
            printf("X.X");
            break;
            case 9:
            printf("X.X");
            break;
        }
        if(i < n-1) printf(".");
    }
    printf("\n");
    for(int i = 0;i < n;i++)
    {
        int x = a[i];
        switch(x)
        {
            case 0:
            printf("X.X");
            break;
            case 1:
            printf("..X");
            break;
            case 2:
            printf("XXX");
            break;
            case 3:
            printf("XXX");
            break;
            case 4:
            printf("XXX");
            break;
            case 5:
            printf("XXX");
            break;
            case 6:
            printf("XXX");
            break;
            case 7:
            printf("..X");
            break;
            case 8:
            printf("XXX");
            break;
            case 9:
            printf("XXX");
            break;
        }
        if(i < n-1) printf(".");
    }
    printf("\n");
    for(int i = 0;i < n;i++)
    {
        int x = a[i];
        switch(x)
        {
            case 0:
            printf("X.X");
            break;
            case 1:
            printf("..X");
            break;
            case 2:
            printf("X..");
            break;
            case 3:
            printf("..X");
            break;
            case 4:
            printf("..X");
            break;
            case 5:
            printf("..X");
            break;
            case 6:
            printf("X.X");
            break;
            case 7:
            printf("..X");
            break;
            case 8:
            printf("X.X");
            break;
            case 9:
            printf("..X");
            break;
        }
        if(i < n-1) printf(".");
    }
    printf("\n");
    for(int i = 0;i < n;i++)
    {
        int x = a[i];
        switch(x)
        {
            case 0:
            printf("XXX");
            break;
            case 1:
            printf("..X");
            break;
            case 2:
            printf("XXX");
            break;
            case 3:
            printf("XXX");
            break;
            case 4:
            printf("..X");
            break;
            case 5:
            printf("XXX");
            break;
            case 6:
            printf("XXX");
            break;
            case 7:
            printf("..X");
            break;
            case 8:
            printf("XXX");
            break;
            case 9:
            printf("XXX");
            break;
        }
        if(i < n-1) printf(".");
    }
    printf("\n");
    return 0;
}

思路是按照5行各个输出,按照样例检查了输出的应该没问题,但测试就全错。


by Missdie @ 2023-11-14 16:41:54

@xi_inluogu 你这个输不进去,把

scanf("%d",&x);

改成

scanf("%1d",&x);

by kevinchw @ 2023-11-14 16:43:36

长度为n,你为啥输了n个整数?


by xi_inluogu @ 2023-11-14 16:45:03

@Missdie 大佬为啥原来的输不进去改成这样就能输进去了啊


by xi_inluogu @ 2023-11-14 16:46:34

@kevinchw 这是输入一行数的意思吗?


by Missdie @ 2023-11-14 16:46:45

@xi_inluogu 蛤,因为%1d就是占位一位整数啊


by Missdie @ 2023-11-14 16:47:24

@xi_inluogu 当然也可以字符串读入


by xi_inluogu @ 2023-11-14 16:49:16

@Missdie 已经懂了,谢谢佬


by xi_inluogu @ 2023-11-14 16:49:47

@kevinchw 已经懂了,谢谢佬


|