比较简单的一道题目,首先由输入的第i行计算出第i+1行的所有数据,然后由第i+1行反推第i行与第i+1行之间的数据,具体实现见如下代码(写的有点繁琐了......):
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;
int main(){
int N;
cin >> N;
while (N--){
int data1[5][5];
int amount = 0;
for (int i = 0; i < 5; i++){
amount++;
for (int j = 0; j < amount; j++) cin >> data1[i][j];
}
int res[9][9];
amount = 0;
for (int i = 0; i < 4; i++){
amount++;
int row1 = i * 2, row2 = (i + 1) * 2;
for (int j = 0; j < amount; j++){
res[row1][j * 2] = data1[i][j];
res[row2][j * 2] = data1[i + 1][j];
}
res[row2][amount * 2] = data1[i + 1][amount];
for (int j = 0; j < amount; j++){
res[row2][j * 2 + 1] = (res[row1][j * 2] - res[row2][j * 2] - res[row2][j * 2 + 2]) / 2;
}
int row3 = row2 - 1;
for (int j = 0; j < amount * 2; j++){
res[row3][j] = res[row2][j] + res[row2][j + 1];
}
}
amount = 0;
for (int i = 0; i < 9; i++){
amount++;
for (int j = 0; j < amount-1; j++){
cout << res[i][j] << " ";
}
cout << res[i][amount - 1] << endl;
}
}
return 0;
}