数字切分有误,求解疑

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

mmnBilibili @ 2024-06-17 21:01:16

这个最开始的数字切分出问题,后面的数字打印没问题

改了好几遍,求解疑 直接上WA代码

#include<bits/stdc++.h>
using namespace std;
int bit[105];
int main(){
    int n,re=0;
    long long ci;
    cin>>n>>ci;
    for (int i=0;;i++){
        while (ci!=0){
            bit[i]=ci%10;
            ci/=10;
            re++;
        }
        break;
    }
    int now;
    for (int i=re;i>-1;i--){                //first
        now=bit[i];
        switch(now){
            case 0:cout<<"XXX";break;
            case 1:cout<<"..X";break;
            case 2:cout<<"XXX";break;
            case 3:cout<<"XXX";break;
            case 4:cout<<"X.X";break;
            case 5:cout<<"XXX";break;
            case 6:cout<<"XXX";break;
            case 7:cout<<"XXX";break;
            case 8:cout<<"XXX";break;
            case 9:cout<<"XXX";break;
        }
        if(i!=re-1){
            cout<<".";
        }
    }
    cout<<endl;
    for (int i=re;i>-1;i--){                //second
        now=bit[i];
        switch(now){
            case 0:cout<<"X.X";break;
            case 1:cout<<"..X";break;
            case 2:cout<<"..X";break;
            case 3:cout<<"..X";break;
            case 4:cout<<"X.X";break;
            case 5:cout<<"X..";break;
            case 6:cout<<"X..";break;
            case 7:cout<<"..X";break;
            case 8:cout<<"X.X";break;
            case 9:cout<<"X.X";break;
        }
        if(i!=re-1){
            cout<<".";
        }
    }
    cout<<endl;
    for (int i=re;i>-1;i--){                //third
        now=bit[i];
        switch(now){
            case 0:cout<<"X.X";break;
            case 1:cout<<"..X";break;
            case 2:cout<<"XXX";break;
            case 3:cout<<"XXX";break;
            case 4:cout<<"XXX";break;
            case 5:cout<<"XXX";break;
            case 6:cout<<"XXX";break;
            case 7:cout<<"..X";break;
            case 8:cout<<"XXX";break;
            case 9:cout<<"XXX";break;
        }
        if(i!=re-1){
            cout<<".";
        }
    }
    cout<<endl;
    for (int i=re;i>-1;i--){                //fourth
        now=bit[i];
        switch(now){
            case 0:cout<<"X.X";break;
            case 1:cout<<"..X";break;
            case 2:cout<<"X..";break;
            case 3:cout<<"..X";break;
            case 4:cout<<"..X";break;
            case 5:cout<<"..X";break;
            case 6:cout<<"X.X";break;
            case 7:cout<<"..X";break;
            case 8:cout<<"X.X";break;
            case 9:cout<<"..X";break;
        }
        if(i!=re-1){
            cout<<".";
        }
    }
    cout<<endl;
    for (int i=re;i>-1;i--){                //fifth
        now=bit[i];
        switch(now){
            case 0:cout<<"XXX";break;
            case 1:cout<<"..X";break;
            case 2:cout<<"XXX";break;
            case 3:cout<<"XXX";break;
            case 4:cout<<"..X";break;
            case 5:cout<<"XXX";break;
            case 6:cout<<"XXX";break;
            case 7:cout<<"..X";break;
            case 8:cout<<"XXX";break;
            case 9:cout<<"XXX";break;
        }
        if(i!=re-1){
            cout<<".";
        }
    }
//  cout<<endl;
    return 0;
}

by 0x3F @ 2024-06-17 21:22:53

@mmnBilibili long long 你 100 位存的下?


by donnieguo @ 2024-06-17 21:29:47

@mmnBilibili 100位long long存不下


by mmnBilibili @ 2024-06-19 21:03:28

??? 这意思是要用高精?但我只是个刚学到多维数组的蒟蒻,高精一点都没学啊。。。


by mmnBilibili @ 2024-06-19 21:04:28

有没有不用高精的方法捏?


by Bismuth_Sulfate @ 2024-07-08 11:15:46

这怎么可能用到高精......你用个string存下整个数字不就行了?


by Bismuth_Sulfate @ 2024-07-08 11:19:57

而且你都用到bit数组了,你改成bit字符串然后直接读入bit不就解决了?(不过需要改下switch里的条件)


by LeonTexius @ 2024-07-18 11:36:34

@mmnBilibili 何必费劲切分 直接输入不行吗 用bit存每一位的数字


by LeonTexius @ 2024-07-18 11:45:44

@mmnBilibili 搞错了


by mmnBilibili @ 2024-07-21 09:36:49

@AshtonHuang 谢谢,已经会了


|