为啥无法正常显示

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

chenglan28 @ 2024-12-15 20:57:35

#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    char arr[5][400];
    int p = 0;//浮标
    for(int i = 0;i<n;i++){
        char d;
        scanf("%c",&d);
        if(d == 0){
            arr[0][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[2][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 1){
            arr[0][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[2][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 3){
            arr[0][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[2][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = '.';arr[0][p+3] = '.';
            arr[4][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 3){
            arr[0][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[2][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 4){
            arr[0][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[2][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 5){
            arr[0][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = '.';arr[0][p+3] = '.';
            arr[2][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 6){
            arr[0][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = '.';arr[0][p+3] = '.';
            arr[2][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 7){
            arr[0][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[2][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 8){
            arr[0][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[2][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        else if(d == 9){
            arr[0][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[1][p] = 'X';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[2][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[3][p] = '.';arr[0][p+1] = '.';arr[0][p+2] = 'X';arr[0][p+3] = '.';
            arr[4][p] = 'X';arr[0][p+1] = 'X';arr[0][p+2] = 'X';arr[0][p+3] = '.';
        }
        p+=4;
    }
    for(int j = 0;j<5;j++){
        for(int k = 0;k<n*4-1;k++){
            cout << arr[j][k];
        }
        cout << "\n";
    }
    return 0;
}

|