shunfurh
编程介的小学生
2017-10-25 13:26

Difference between Triplets

  • as
  • lines
  • each

Description
For every pair of triplets, Ta = (Ia, Ja, Ka) and Tb = (Ib,Jb, Kb), we define the difference value betweenTa and Tb as follows:
D(Ta, Tb) = max {Ia −Ib, Ja − Jb, Ka −Kb} − min {Ia − Ib, Ja − Jb, Ka − Kb}
Now you are given N triplets, could you write a program to calculate the sum of the difference values between every unordered pair of triplets?
Input
The input consists of several test cases.
Each test case begins with a line containing an integer N, denotes the number of triplets. Assume that we number the triplets asT1, T2, ... , TN. Then, there are followingN lines, each line contains three integers, giving the elements of each triplet.
A case with N = 0 indicates the end of the input.
Output
For each case, output a line with the sum of difference values between every unordered pair of triplets.
Sample Input
2
1 2 3
3 2 1
3
1 3 2
4 0 7
2 2 9
0
Sample Output
4
20

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐