弱校联萌十一大决战之背水一战A A Big Dinner

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


这个题考的全排列 而且是升序的 自己开始还想傻乎乎的枚举各种情况 还把升序这个条件给忘了

其实之前自己就用过 next_permutation 1027Ignatius and the Princess II 到底还不是自己做出来的 印象不深啊 

自动去重的功能好强大 ╭(╯^╰)╮

#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int A[3];
void show(){
	for(int i=0;i<2;i++){
		printf("%d ",A[i]);
	}
	printf("%d\n",A[2]);
}
int main(){
    int n,t=1;
    cin>>n;
    while(n--){
        for(int i=0;i<3;i++) scanf("%d",&A[i]);
        sort(A,A+3);
        printf("Case #%d:\n",t++);
        do{
		   show();
	    }while(next_permutation(A,A+3));
    }
	return 0;
}


你可能感兴趣的:(ACM,STL)