/*
题目:对于一个给定的数组,找到目标在这个数组第k出现的 位置
方法: 遍历整个数组,用一个变量cnt记录出现的次数
*/
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, k, m;
int a[N][N];
void solve() {
int n;
cin >> n;
for (int i =0; i < n - 1; i ++) {
for (int j =0; j < n -1; j ++)
a[i][j] = (i + j) % ( n - 1) + 1;
}
for (int i = 0; i < n -1; i ++) {
a[i][n - 1] = a[n - 1][i] = a[i][i];
a[i][i] = 0;
}
for (int i = 0; i < n ; i ++)
for (int j = 0; j < n; j ++)
if (j < n - 1)
cout << a[i][j] << " ";
else cout << a[i][j] << endl;
}
int main () {
int t;
t = 1;
while (t --) solve();
return 0;
}
从按照顺序的角度开始想。