A Big Dinner 枚举

点击打开链接

 

 

Description

As is known to all, an ACM team consists of three members and to know more about each others, they often go to a restaurant to have a big dinner.

Each member ordered himself only one dish, and waited for it. However, the restaurant serves in a strange way. They cooked the meal in a random order. Besides, if some same dishes appear consecutively, the cooks will cook the dishes at the same time.

Given the ordered three dishes, can you output every possible order the restaurant severed.

Input


The first line of the input is T(1 <= T <= 100), which stands for the number of test cases you need to solve.

For each case, there are three integers(the integers are all positive and less than 10) in the single line, which stand for the dish ID for each person.

Output


Every case contains one line with three integer standing for the kinds of ordered dishes.

For every test case, you should output "Case #t:" in the first line, where t indicates the case number and counts from 1. Then output all the possible order the restaurant can serve in the ascending order.

Sample Input

2
2 1 2
1 7 5

Sample Output

Case #1:
1 2 2
2 1 2
2 2 1
Case #2:
1 5 7
1 7 5
5 1 7
5 7 1
7 1 5
7 5 1

Source

Sichuan State Programming Contest 2012

#include<stdio.h>
#include<algorithm>
using namespace std;
int s[4];
int cmp(int a,int b)
{
    return a<b;
}
int main()
{
    int t;
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {
        for(int j=0;j<3;j++)
        scanf("%d",&s[j]);
        sort(s,s+3,cmp);
        printf("Case #%d:\n",i);
        if(s[0]!=s[1]&&s[1]!=s[2])
        {
            for(int k=0;k<3;k++)
            for(int l=0;l<3;l++)
            for(int m=0;m<3;m++)
            {
                if(k!=l&&l!=m&&k!=m)
                printf("%d %d %d\n",s[k],s[l],s[m]);
            }
        }
        else if(s[0]==s[1]&&s[1]==s[2])
        {
            printf("%d %d %d\n",s[0],s[1],s[2]);
        }
        else if(s[0]!=s[1]&&s[1]==s[2])
        {
            printf("%d %d %d\n",s[0],s[1],s[2]);
            printf("%d %d %d\n",s[1],s[0],s[2]);
            printf("%d %d %d\n",s[1],s[2],s[0]);
        }
        else
        {
            printf("%d %d %d\n",s[0],s[1],s[2]);
            printf("%d %d %d\n",s[0],s[2],s[1]);
            printf("%d %d %d\n",s[2],s[1],s[0]);
        }

    }
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值