Day13 AcWing 754. 平方矩阵 II
思路
- 找规律
拓展
- AcWing 753. 平方矩阵 I
- AcWing 755. 平方矩阵 III
- AcWing 727. 菱形
- AcWing 748 - 752
- AcWing 3154. 打印大X
- AcWing 118. 分形
代码
算法1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| #include <iostream> #include <cstring> #include <algorithm>
using namespace std;
const int N = 110;
int n; int a[N][N];
int main() { while (cin >> n, n) { for (int i = 1; i <= n; i ++ ) { for (int j = i, k = 1; j <= n; j ++, k ++ ) { a[i][j] = k; a[j][i] = k; } }
for (int i = 1; i <= n; i ++ ) { for (int j = 1; j <= n; j ++ ) cout << a[i][j] << ' '; cout << endl; } cout << endl; }
return 0; }
|
算法2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include <iostream> #include <cstring> #include <algorithm>
using namespace std;
const int N = 110;
int n; int main() { while (cin >> n, n) { for (int i = 1; i <= n; i ++ ) { for (int j = i; j >= 1; j -- ) cout << j << ' '; for (int j = i + 1; j <= n; j ++ ) cout << j - i + 1 << ' '; cout << endl; } cout << endl; }
return 0; }
|
算法3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include <iostream> #include <cstring> #include <algorithm>
using namespace std;
const int N = 110;
int n; int main() { while (cin >> n, n) { for (int i = 1; i <= n; i ++ ) { for (int j = 1; j <= n; j ++ ) cout << abs(i - j) + 1 << ' '; cout << endl; } cout << endl; }
return 0; }
|