首页 > 其他 > 详细

PAT 1011

时间:2014-02-14 19:01:25      阅读:415      评论:0      收藏:0      [点我收藏+]

1011. World Cup Betting (20)

With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.

Chinese Football Lottery provided a "Triple Winning" game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results -- namely W for win, T for tie, and L for lose. There was an odd assigned to each result. The winner‘s odd would be the product of the three odds times 65%.

For example, 3 games‘ odds are given as the following:

 W    T    L 
1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1

To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. If each bet takes 2 yuans, then the maximum profit would be (4.1*3.0*2.5*65%-1)*2 = 37.98 yuans (accurate up to 2 decimal places).

Input

Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to W, T and L.

Output

For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.

Sample Input
1.1 2.5 1.7 
1.2 3.0 1.6
4.1 1.2 1.1
Sample Output
T T W 37.98 

代码

 

bubuko.com,布布扣
 1 #include <stdio.h>
 2 
 3 int findMaxIndex(double*,int);
 4 int main()
 5 {
 6     double odd[3],profit;
 7     int index1,index2,index3;
 8     const char outPut[3] = {W,T,L};
 9     while(scanf("%lf%lf%lf",&odd[0],&odd[1],&odd[2]) != EOF){
10         index1 = findMaxIndex(odd,3);
11         profit = odd[index1];
12         scanf("%lf%lf%lf",&odd[0],&odd[1],&odd[2]);
13         index2 = findMaxIndex(odd,3);
14         profit *= odd[index2];
15         scanf("%lf%lf%lf",&odd[0],&odd[1],&odd[2]);
16         index3 = findMaxIndex(odd,3);
17         profit *= odd[index3];
18         printf("%c ",outPut[index1]);
19         printf("%c ",outPut[index2]);
20         printf("%c ",outPut[index3]);
21         profit = (profit * 0.65 - 1) * 2;
22         printf("%.2lf\n",profit);
23     }
24     return 0;
25 }
26 
27 int findMaxIndex(double *dArray,int n)
28 {
29     if(n == 0)
30         return -1;
31     int index = 0;
32     double maxValue = dArray[0];
33     int i;
34     for(i=1;i<n;++i){
35         if(maxValue < dArray[i]){
36             index = i;
37             maxValue = dArray[i];
38         }
39     }
40     return index;
41 }
bubuko.com,布布扣

PAT 1011

原文:http://www.cnblogs.com/boostable/p/pat_1011.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!