本来想“暴力枚举”直接列数组,没想到只得了四十分,求助个位dalao神犇!
#include <bits/stdc++.h>
using namespace std;
int F[10] = {0,1,3,6,10,15,21,28,36,45};
int V[10] = {1,2,4,7,11,16,22,29,37,46};
int lianjia(int n)
{
int sum = 0;
for (int i = 1; i <= n; i++) sum += i;
return sum;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= (int)pow(n,2); i++)
{
if (i <= 9) cout << 0 << i;
else cout << i;
if (i % n == 0) cout << endl;
}
cout << endl;
int line = n - 1;
for (int i = 1; i <= lianjia(n); i++)
{
for (int j = 0; j < 10; j++)
{
if (i == V[j])
{
cout << setw(line * 2 + 1);
line--;
}
}
if (i <= 9) cout << 0 << i;
else cout << i;
for (int j = 0; j < 10; j++)
{
if (i == F[j]) cout << endl;
}
}
return 0;
}