1 条题解
-
0
本题考察双重for循环的应用。 我们只需要用两个for循环,判断当前位置是否为对角线即可。 上代码:
#include <bits/stdc++.h> using namespace std; int n; int main(void) { cin >> n; for (int i = 0;i < n;++i) { for (int j = 0;j < n;++j) { if (i == j || i + j == n - 1) { cout << 'X'; } else { cout << ' '; } } cout << '\n'; } return 0; }
- 1
信息
- ID
- 103
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 4
- 已通过
- 3
- 上传者