全wa求助,各位大佬

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

lvcb248 @ 2024-08-27 20:16:16

#include<stdio.h>
int main()
{
    int n=0,i=0,u=0;
    int a[100];
    scanf("%d",&n);

    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
    }

    for(i=0;i<n-1;i++)
    {
         switch(a[i])
         {
            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;

          } 
    }
        switch(a[n-1])
         {
            case  0:
            printf("XXX\n");
            break;
            case  1:
            printf("..X\n");
                break;
            case  2:
            printf("XXX\n");
                break;
            case  3:
            printf("XXX\n");
                break;
            case  4:
            printf("X.X\n");
                break;
            case  5:
            printf("XXX\n");
                break;
            case  6:
            printf("XXX\n");
                break;
            case  7:
            printf("XXX\n");
                break;
            case  8:
            printf("XXX\n");
                break;
            case  9:
            printf("XXX\n");
            break;

          } 

     for(i=0;i<n-1;i++)
    {
         switch(a[i])
         {
            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;

          } 

    }
         switch(a[n-1])
         {
            case  0:
            printf("X.X\n");
            break;
            case  1:
            printf("..X\n");
                break;
            case  2:
            printf("..X\n");
                break;
            case  3:
            printf("..X\n");
                break;
            case  4:
            printf("X.X\n");
                break;
            case  5:
            printf("X..\n");
                break;
            case  6:
            printf("X..\n");
                break;
            case  7:
            printf("..X\n");
                break;
            case  8:
            printf("X.X\n");
                break;
            case  9:
            printf("X.X\n");
            break;

          } 

     for(i=0;i<n-1;i++)
    {
         switch(a[i])
         {
            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;

          } 

    }

         switch(a[n-1])
         {
            case  0:
            printf("X.X\n");
            break;
            case  1:
            printf("..X\n");
                break;
            case  2:
            printf("XXX\n");
                break;
            case  3:
            printf("XXX\n");
                break;
            case  4:
            printf("XXX\n");
                break;
            case  5:
            printf("XXX\n");
                break;
            case  6:
            printf("XXX\n");
                break;
            case  7:
            printf("..X\n");
                break;
            case  8:
            printf("XXX\n");
                break;
            case  9:
            printf("XXX\n");
            break;

          } 
     for(i=0;i<n-1;i++)
    {
         switch(a[i])
         {
            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;

          } 

    }

          switch(a[n-1])
         {
            case  0:
            printf("X.X\n");
            break;
            case  1:
            printf("..X\n");
                break;
            case  2:
            printf("X..\n");
                break;
            case  3:
            printf("..X\n");
                break;
            case  4:
            printf("..X\n");
                break;
            case  5:
            printf("..X\n");
                break;
            case  6:
            printf("X.X\n");
                break;
            case  7:
            printf("..X\n");
                break;
            case  8:
            printf("X.X\n");
                break;
            case  9:
            printf("..X\n");
            break;

          } 
     for(i=0;i<n-1;i++)
    {
         switch(a[i])
         {
            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;

          } 

    }
          switch(a[n-1])
         {
            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;
        }

    return  0;
 } 

by Curry_mvp @ 2024-08-27 20:17:18


by dongzirui0817 @ 2024-08-27 20:28:01

@lvcb248 请注意输入方式。


by Yxy7952 @ 2024-08-27 20:31:02

@lvcb248

???????,不是,楼主,输入都有问题,建议做字符串入门题


by Yxy7952 @ 2024-08-27 20:32:15

@dongzirui0817

楼主是真逆天,写了这么多,样例都有问题,就敢交


by dongzirui0817 @ 2024-08-27 20:32:58

@lvcb248 你程序还有些问题……


by dongzirui0817 @ 2024-08-27 20:37:37

@lvcb248 第337行\ printf("XXX");\ 改成\ printf("XXX.");


by lvcb248 @ 2024-08-27 22:18:03

@yixingyou 我在dev c++样例过了哩,可以说说我的输入哪里有问题吗,至于字符串我还没学


by Yxy7952 @ 2024-08-28 09:46:32

@lvcb248 \

给楼主讲一下,这是样例:

10
0123456789

这是你的输入:

int a[100];
scanf("%d",&n);
for(i=0;i<=n-1;i++){
   scanf("%d",&a[i]);
}

这是题目原话:

第二行输入一个长度为 n 的自然数

显然样例的第二行是 一个数字 或者可以理解为 一串字符串 ,但你的输入方式却理解成了有 N 个数字,这个输入都出现了问题。

楼主应该先把输入的第二行当作字符串处理,并手动改为 N 个数字的形式存储。


by lvcb248 @ 2024-08-28 14:34:31

@yixingyou 噢噢,懂了


|