为什么就不对呢????

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

LiBinnn @ 2020-03-16 16:23:21

#include <iostream>
#include <string>
#include <cstdio>
using namespace std;

string line1[10] = {"XXX","..X","XXX","XXX","X.X","XXX","XXX","XXX","XXX","XXX"};
string line2[10] = {"X.X","..X","..X","..X","X.X","X..","X..","..X","X.X","X.X"};
string line3[10] = {"X.X","..X","XXX","XXX","XXX","XXX","XXX","..X","XXX","XXX"};
string line4[10] = {"X.X","..X","X..","..X","..X","..X","X.X","..X","X.X","..X"};
string line5[10] = {"XXX","..X","XXX","XXX","..X","XXX","XXX","..X","XXX","XXX"};
int main(){
    string str;
    int num[200];
    int n;
    cin>>n;
    getchar();
    getline(cin,str);
    for(int i=0;i<n;i++){
        num[i] = str[i]-'0';
    }

    //1
    for(int i=0;i<n;i++){
        if(i==n-1){
            cout<<line1[num[i]];
        }else{
            cout<<line1[num[i]]<<".";
        }
    }
    cout<<endl;
    //2
    for(int i=0;i<n;i++){
        if(i==n-1){
            cout<<line2[num[i]];
        }else{
            cout<<line2[num[i]]<<".";
        }
    }
    cout<<endl;
    //3
    for(int i=0;i<n;i++){
        if(i==n-1){
            cout<<line3[num[i]];
        }else{
            cout<<line3[num[i]]<<".";
        }
    }
    cout<<endl;
    //4
    for(int i=0;i<n;i++){
        if(i==n-1){
            cout<<line4[num[i]];
        }else{
            cout<<line4[num[i]]<<".";
        }
    }
    cout<<endl;
    //5
    for(int i=0;i<n;i++){
        if(i==n-1){
            cout<<line5[num[i]];
        }else{
            cout<<line5[num[i]]<<".";
        }
    }
    return 0;
} 

by kevin516 @ 2020-03-16 16:24:47

...


by Lylighte @ 2020-03-16 16:25:28

一个一个字符读入怎样


by Andysun06 @ 2020-03-16 16:26:34

……


by bovine__kebi @ 2020-03-16 16:28:21

。。。。


by liqingyang @ 2020-03-16 16:28:36

@LiBinnn 最后一列没有点!


by liqingyang @ 2020-03-16 16:29:10

您的代码确实丑了点。。。


by Lylighte @ 2020-03-16 16:36:37

getline 这种玄之又玄的东西尽量少用。。。

@LiBinnn


by Lylighte @ 2020-03-16 16:37:40

int n;
    cin>>n;
    cin>>str;
    for(int i=0;i<n;i++){
        num[i] = str[i]-'0';
    }

by LiBinnn @ 2020-03-16 17:20:53

@liqingyang 它要求不是最后一个数后面是没点的吗


by liqingyang @ 2020-03-16 17:26:14

@LiBinnn 那可能是因为您num定义在了main里面


| 下一页