sdau 省赛热身4 A - 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
题目大意:参加省赛得有人请吃饭哦~
题目分析:全排列(貌似需要从小到大排)
code:
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int i,t,a[3];
scanf("%d",&t);
for(i=1;i<=t;i++)
{
scanf("%d%d%d",&a[0],&a[1],&a[2]);
sort(a,a+3);
if(a[0]==a[1]&&a[1]==a[2])
{
printf("Case #%d:\n%d %d %d\n",i,a[0],a[0],a[0]);
}
else if(a[0]==a[1])
{
printf("Case #%d:\n",i);
printf("%d %d %d\n",a[0],a[1],a[2]);
printf("%d %d %d\n",a[0],a[2],a[1]);
printf("%d %d %d\n",a[2],a[1],a[0]);
}
else if(a[1]==a[2])
{
printf("Case #%d:\n",i);
printf("%d %d %d\n",a[0],a[1],a[2]);
printf("%d %d %d\n",a[1],a[0],a[1]);
printf("%d %d %d\n",a[2],a[1],a[0]);
}
else
{
printf("Case #%d:\n",i);
printf("%d %d %d\n",a[0],a[1],a[2]);
printf("%d %d %d\n",a[0],a[2],a[1]);
printf("%d %d %d\n",a[1],a[0],a[2]);
printf("%d %d %d\n",a[1],a[2],a[0]);
printf("%d %d %d\n",a[2],a[0],a[1]);
printf("%d %d %d\n",a[2],a[1],a[0]);
}
}
return 0;
}PS:省赛倒计时4days整……祈祷ing……
本文探讨了一个关于ACM团队成员在餐厅等待所点菜品的问题。考虑到餐厅可能会按任意顺序或连续相同菜品一起烹饪的情况,文章提供了一种算法来找出所有可能的服务顺序。
454

被折叠的 条评论
为什么被折叠?



