很迷,求大佬看一眼

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

cmd137 @ 2023-10-28 18:26:13

先准被一个一个数字做,目前只写了0的,当输入2 0 0的时候就变样了,(1 0 正确输出)

不便放图,麻烦大佬亲手一试 源码如下:

#include <iostream>
#include <string.h>
using namespace std;

char a[400][5];

int main() {
    int n;
    cin >> n;
    memset(a, '.', sizeof(a));

    int x = 1;
    int y = 1;

    for (int i = 1; i <= n; i++) {
        char t ;
        cin >> t;
        switch (t) {
            case '0':
                a[x][y] = 'X';
                a[x + 1][y] = 'X';
                a[x + 2][y] = 'X';
                a[x + 3][y] = 'X';
                a[x + 4][y] = 'X';

                a[x][y + 1] = 'X';
                a[x + 1][y + 1] = '.';
                a[x + 2][y + 1] = '.';
                a[x + 3][y + 1] = '.';
                a[x + 4][y + 1] = 'X';

                a[x][y + 2] = 'X';
                a[x + 1][y + 2] = 'X';
                a[x + 2][y + 2] = 'X';
                a[x + 3][y + 2] = 'X';
                a[x + 4][y + 2] = 'X';
                break;
        }

        y += 4;

    }

    for (int i = 1; i <= 5; i++) {
        for (int j = 1; j <= 3 * n + n - 1; j++) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
}

by suxiaozhou @ 2023-10-28 19:14:13

char a[11][410];

而不是

char a[400][5];

by cmd137 @ 2023-10-28 19:37:06

@suxiaozhou 感谢您!


by suxiaozhou @ 2023-10-28 21:44:59

@cmd137 另外记得别漏了return 0;


by cmd137 @ 2023-10-29 15:38:08

@suxiaozhou 能讲一下return 0有什么用吗,除了一部分特殊情况需要return 0提前结束,我实在是不知道末尾写个return 0有什么用


by K_srh @ 2023-10-29 17:56:05

@cmd137

让程序最终返回0,是竞赛代码的硬性要求


by cmd137 @ 2023-10-29 18:50:10

@liuhaoran2 明白


|