发散思维,要从多个方向考虑问题~ 你可以考虑坐标之间的关系,或者坐标与数的关系,或者位置的关系:比如图形对称啦,或者可以同时往几个方向走啦之类的
方法一:from 闫老师~tql~ 同时往右和下走!
#include<iostream>
using namespace std;
int main()
{
int a[110][110];
int n;
while(cin >> n, n)
{
for (int i = 0; i < n; i ++ )
{
int k = 1;
for (int j = i; j < n; j ++ )
a[i][j] = a[j][i] = k ++ ;
}
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < n; j ++ ) cout << a[i][j] << ' ';
cout << endl;
}
cout << endl;
}
return 0;
}
方法二:看别的dl的做法 看坐标和数的关系
while(cin >> n, n)
{
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < n; j ++ )
a[i][j] = abs(i - j) + 1;
}
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j < n; j ++ ) cout << a[i][j] << ' ';
cout << endl;
}
cout << endl;
}
大家都好强555…这都是怎么想到的