哄堂大笑了,为什么全错?

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

sodiums @ 2021-04-11 00:08:31

#include <iostream>
#include <cstdio>
using namespace std;
#define fill "XXX"
#define zy "X.X"
#define y "..X"
#define z "X.."
int main ()
{
    int n;
    cin>>n;
    int number[n+1];
    for (int i=0;i<=n;i++) number[i]=getchar();
    //number - 48 实际值
    //number[1] 为第一个数字
    for (int i=0;i<5;i++)
    {
        for (int j=1;j<=n;j++)
        {
            if (number[j]-48==0 && (i== 0 || i==4 ))
            {
                cout << fill;
            }
            else if (number[j]-48==0 && !(i== 0 || i==4 ))
            {
                cout <<zy;
            }
            if (number[j]-48==1)
            {
                cout <<y;
            }
            if (number[j]-48==2 && i==1)
            {
                cout <<y;
            }
            else if (number[j]-48==2 && !(i==1 || i==3))
            {
                cout<<fill;
            }
            else if (number[j]-48==2 && i==3)
            {
                cout <<z;
            }
            if (number[j]-48==3 && !(i==1 || i==3))
            {
                cout <<fill;
            }
            else if (number[j]-48==3 && (i==1 ||i==3))
            {
                cout << y;
            }
            if (number[j]-48==4 && (i==0 || i==1) )
            {
                cout <<zy;
            }
            else if (number[j]-48==4 && i==2) cout << fill;
            else if (number[j]-48==4 && (i==3 || i==4)) cout <<y;
            if (number[j]-48==5 && i==1) cout <<z;
            else if (number[j]-48==5 && i==3) cout<<y;
            else if (number[j]-48==5 && !(i==1 || i==3 )) cout <<fill;
            if (number[j]-48==6 && i==1) cout <<z;
            else if (number[j]-48==6 && i==3) cout << zy;
            else if (number[j]-48==6 && !(i==1 || i==3)) cout <<fill;
            if (number[j]-48==7 && i==0) cout <<fill;
            else if (number[j]-48==7 && i!=0) cout <<y;
            if (number[j]-48==8 && i==1) cout <<zy;
            else if (number[j]-48==8 && i==3) cout <<zy;
            else if (number[j]-48==8 && !(i==3||i==1)) cout <<fill;
            if (number[j]-48==9 && i==1) cout <<zy;
            else if (number[j]-48==9 && i==3) cout << y;
            else if (number[j]-48==9 && !(i==3||i==1)) cout <<fill;
            if (j!= n)
            {
                cout <<".";   
            }
        }

        cout <<endl;
    }
    return 0;
}

by haraki @ 2021-04-11 00:24:51

@sodiums 在前面再加一个getchar

    int number[n+1];
    for (int i=0;i<=n;i++) number[i]=getchar();

->

  int number[n+1];
  getchar();
    for (int i=0;i<=n;i++) number[i]=getchar();

估计是数据在windows上造的 换行是\r\n(貌似是 所以读换行要读两个 你前面用number[0]读了一个 所以只加一个getchar


by sodiums @ 2021-04-11 00:26:41

@haraki_argon 谢谢及时回复~就在我通过的时候刚好收到消息,实在太巧了..


by justinjia @ 2021-04-11 06:57:35

@sodiums 你们是如何做到半夜上你谷的(雾


by 左丞相953105 @ 2021-04-11 09:05:17

@justinjia 这不是基本操作吗?


by useless_man @ 2021-11-30 13:57:07

@左丞相953105 就你小子会说话!!(doge,doge,doge)


|