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 }

  • 相关阅读:
    python操作redis
    Redis 安装试用
    python操作RabbitMQ
    pycharm快捷键
    各种python使用的坑
    RabbitMQ安装和使用
    Moosefs基本概念
    mesos客户端重新注册导致容器状态为staged
    初学Android 二 创建项目以及目录结构
    【杭电】[5631]Rikka with Graph
  • 原文地址:https://www.cnblogs.com/boostable/p/pat_1011.html
Copyright © 2011-2022 走看看