2 条题解
-
1
谁说要用二维数组的?我不用数组都行,就是极端思想嘛(类似于反弹思想或曲折思想那种),🍳(谐音梗,煎蛋=简单)!
已AC,请放心食用
#include <iostream> using namespace std; int main() { int n, x, s; cin >> n; for (int i = 1; i <= n; i++) { x = i; s = 0; for (int j = 1; j <= n; j++) { cout << " " << x; if (x == 1) { s = 0; } if (x == n) { s = 1; } if (s == 0) { x++; } else { x--; } } cout << endl; } return 0; }
-
0
#include <iostream> using namespace std; int main() { int n, x; bool flag; cin >> n; int a[n + 1][n + 1]; for (int i = 1; i <= n; i++) { x = i; flag = true; for (int j = 1; j <= n; j++) { a[i][j] = x; if (x + 1 > n) { flag = false; } if (flag) { x++; } else { x--; } } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cout << " " << a[i][j]; } cout << endl; } return 0; }
- 1
信息
- ID
- 193
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 2
- 标签
- 递交数
- 76
- 已通过
- 46
- 上传者