由于这个排列的行数和列数已经固定了,所以比较好找规律,由最下面一行和倒数第三行可以得出最下面一行完整的数排列,所以整个排列就可以递推出来了,my ugly code(我没用上题目中的后几行数据):
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n;cin>>n;
while(n--)
{
int temp,temp1,temp2,temp3,temp4,zhuan[10][10];
int a,b,c,d,e,f,g,h,i;
cin>>temp;cin>>temp;cin>>temp;
cin>>temp;cin>>temp;cin>>temp;
cin>>temp1;cin>>temp2;cin>>temp3;
cin>>temp4;
cin>>a>>c>>e>>g>>i;
b = (temp1 - a - c) / 2;
d = (temp2 - e - c) / 2;
f = (temp3 - e - g) / 2;
h = (temp4 - g - i) / 2;
zhuan[0][0] = a;zhuan[0][1] = b;zhuan[0][2] = c;
zhuan[0][3] = d;zhuan[0][4] = e;zhuan[0][5] = f;
zhuan[0][6] = g;zhuan[0][7] = h;zhuan[0][8] = i;
for(int j = 1;j <=8 ;j++)
for(int i = 0;i < 9 - j;i++)
zhuan[j][i] = zhuan[j - 1][i] + zhuan[j - 1][i + 1];
for(int i = 8;i >= 0;i--)
{
for(int j = 0;j < 9 - i;j++)
{
if(j == 0) printf("%d",zhuan[i][j]);
else printf(" %d",zhuan[i][j]);
}
printf("\n");
}
}
return 0;
}