#CS40111. 阅读程序-1模拟策略-11
阅读程序-1模拟策略-11
阅读程序
注意:切勿用电脑直接运行代码得出答案,请用大脑+笔+纸运行代码答题,否则是在浪费你的时间。
第一节:模拟策略
第11题【NOIP】2017
#include <iostream>
using namespace std;
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;
return 0;
}
●判断题
(1)11行改为n=(n<<1)-1;程序运行结果不变。
( )
{{ select(11-1) }}
- 对
- 错
(2)输出的数字有n(n是最初输入的数值)个。
( )
{{ select(11-2) }}
- 对
- 错
(3)将12行的i++改为++i程序运行结果不变。
( )
{{ select(11-3) }}
- 对
- 错
(4)将06~08行去掉,程序运行结果不变。
{{ select(11-4) }}
- 对
- 错
●选择题
(5)输入为3时,输出为( )。
{{ select(11-5) }}
- 17 24 1 8 15
- 17 21 3 5 2
- 1 5 36 7 5
- 17 2 8 3 1
(6)输入为4时,输出为( )。
{{ select(11-6) }}
- 30 39 48 1 10 19 28
- 24 39 48 1 10 19 28
- 30 39 48 1 5 19 14
- 30 39 24 1 10 19 28