zoukankan      html  css  js  c++  java
  • PAT 1011

    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 

    代码

     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 ",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 }

  • 相关阅读:
    WF4.0 基础篇 (十九) Persistence 持久化
    WF是什么系列之 [ WF控制逻辑线路的算法]
    控制3D模型的例子
    企业信息化建设发展报告
    WF是什么系列之 [ WF控制机械手臂 (3D模型) ]
    WF4.0 RC 对比 Beta2 的变化
    企业信息化所面临的问题
    企业应用的SOA时代
    WF4.0 基础篇 (二十三) 范型Activity
    WF4.0 应用篇(三) IActivityTemplateFactory
  • 原文地址:https://www.cnblogs.com/boostable/p/pat_1011.html
Copyright © 2011-2022 走看看