题库 信息学奥赛题库 题目列表 2017年noip提高组初赛阅读程序题:#include <...
填空题

2017年noip提高组初赛阅读程序题:

#include <iostream>
usingnamespacestd;
int main() {
    int n, i, j, x, y, nx, ny;
    int a[40][40];
    for (i = 0; i < 40; i++)
        for (j = 0; j < 40; j++)
            a[i][j] = 0;
    cin >> n;
    y = 0;
    x = n - 1;
    n = 2 * n - 1;
    for (i = 1; i <= n * n; i++) {
        a[y][x] = i;
        ny = (y - 1 + n) % n;
        nx = (x + 1) % n;
        if ((y == 0 && x == n - 1) || a[ny][nx] != 0)
            y = y + 1;
        else {
            y = ny; x = nx;
        }
    }
    for (j = 0; j < n; j++)
        cout << a[0][j] << " ";
    cout << endl;
    return0;
}

输入:3 

输出:_________

题目信息
阅读程序 2017年 初赛
-
正确率
0
评论
163
点击