AcWing 754. 平方矩阵 II
原题链接
简单
作者:
LingYunX
,
2021-02-24 21:10:15
,
所有人可见
,
阅读 276
// 按行枚举,分段输出
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int a[N][N];
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; j <= n; j ++ ) cout << j - i + 1 << " ";
cout << endl;
}
cout << endl;
}
return 0;
}
// 规律: i行j列的数字结果 = abs(i - j) + 1
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
int a[N][N];
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;
}