AcWing 754. 平方矩阵 II
原题链接
简单
作者:
杨根思
,
2024-11-23 12:06:50
,
所有人可见
,
阅读 1
Drawing from bottom right corner
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int main() {
while (1) {
int dimension = 1;
cin >> dimension;
if(dimension == 0) break;
int f[dimension][dimension];
for (int bottomRight = 0; bottomRight < dimension; bottomRight++) {
if (bottomRight == 0) {
f[dimension - 1][dimension - 1] = 1;
} else {
int xi = dimension - bottomRight - 1;
int yi = dimension - bottomRight - 1;
int value = 1;
for (int i = xi; i < dimension; i++) {
f[i][yi] = value;
value++;
}
value = 1;
for (int y = yi; y < dimension; y++) {
f[xi][y] = value;
value++;
}
}
}
for (int i = 0; i < dimension; i++) {
for (int j = 0; j < dimension; j++) {
printf("%d ", f[i][j]);
}
cout << "\n";
}
cout << "\n";
}
return 0;
}