现在的位置: 首页 > 综合 > 正文

A Big Dinner 枚举

2014年04月05日 ⁄ 综合 ⁄ 共 1674字 ⁄ 字号 评论关闭

点击打开链接

 

 

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;
}

抱歉!评论已关闭.