G: A Towering Problem

题目描述

You’ve been put in charge of an art exhibit from the famous minimalist sculptor J (even his name is minimalist!). J’s work involves the careful layout of vertically dispositioned orthogonal parallelpipeds in a set of tapering obelisks — in other words, he puts smaller boxes on top of larger boxes. His most recent triumph is called “2 by 3’s Decreasing,” in which he has various sets of six boxes arranged in two stacks of three boxes each. One such set is shown below:
J has sent you the art exhibit and it is your job to set up each of the six-box sets at various locations throughout the museum. But when the sculptures arrived at the museum, uncultured barbarians(i.e., delivery men) simply dropped each set of six boxes on the floor, not realizing the aesthetic appeal of their original layout. You need to reconstruct each set of two towers, but you have no idea which box goes on top of the other! All you know is the following: for each set of six, you have the heights of the two towers, and you know that in any tower the largest height box is always on the bottom and the smallest height box is on the top. Armed with this information, you hope to be able to figure out which boxes go together before tomorrow night’s grand opening gala.

输入

The input consists of eight positive integers. The first six represent the heights of the six boxes.
These values will be given in no particular order and no two will be equal.
The last two values (which will never be the same) are the heights of the two towers.
All box heights will be ≤ 100 and the sum of the box heights will equal the sum of the tower heights.

输出

Output the heights of the three boxes in the first tower (i.e., the tower specified by the first tower height in the input), then the heights of the three boxes in the second tower. Each set of boxes should be output in order of decreasing height. Each test case will have a unique answer.

样例输入

12 8 2 4 10 3 25 14

样例输出

12 10 3 8 4 2

CODE:

 

#include <stdio.h>

int main()

{

      int a[6],i,j,k,t1,t2,t;

    for(i=0;i<6;i++)

           scanf("%d",&a[i]);

      scanf("%d",&t1);

      scanf("%d",&t2);

      for(i=0;i<5;i++)

           for(j=i+1;j<6;j++)

                 if(a[i]<a[j])

                 {

                      t=a[i];

                      a[i]=a[j];

                      a[j]=t;

                 }

      for(i=0;i<6;i++)

           for(j=i+1;j<6;j++)

                 for(k=j+1;k<6;k++)

                 {

                      if(a[i]+a[j]+a[k]==t1)

                            printf("%d %d %d ",a[i],a[j],a[k]);

                 }

      for(i=0;i<6;i++)

           for(j=i+1;j<6;j++)

                 for(k=j+1;k<6;k++)

                 {

                      if(a[i]+a[j]+a[k]==t2)

                            printf("%d %d %d\n",a[i],a[j],a[k]);

                 }

    return 0;

}

转载于:https://www.cnblogs.com/shu233/p/5575576.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值