PAT甲级.1011. World Cup Betting (20)

来源:互联网 发布:套利定价知乎 编辑:程序博客网 时间:2024/04/30 18:24

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).

输入格式:

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.

输出格式:

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.

输入样例:

1.1 2.5 1.7
1.2 3.0 1.6
4.1 1.2 1.1

输出样例:

T T W 37.98
PAT链接


思路:

version1.0:

1.结构体存储要用的信息:

struct Game{    double W;    double T;    double L;    double MaxOdds;    char Max = 'W';}res[3];

2.找最大值更新信息:

void Max3(Game res){    MaxOdds = res.W;    if(res.T > MaxOdds)    {        res.MaxOdds = res.T        res.Max = 'T';    }    if(res.L > MaxOdds)    {        res.MaxOdds = res.L;        res.Max = 'L';    }}

version2.0

1.将W , T, L的字符分别用0,1,2对应起来

char S[3] = {'W', 'T', 'L'};

2.输入一个数处理一个数


代码:

version1.0

/*** @tag     PAT_A_1011* @authors R11happy (xushuai100@126.com)* @date    2016-08-10 21:43:16-21:28* @version 1.0* @Language C++* @Ranking  255/2741*/#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>using namespace std;struct Game{  double W;  double T;  double L;  double MaxOdds;  char Max = 'W';}res[3];//3个中找可能性最高的选项void Max3(Game &res){  res.MaxOdds = res.W;  if (res.T > res.MaxOdds)  {    res.MaxOdds = res.T;    res.Max = 'T';  }  if (res.L > res.MaxOdds)  {    res.MaxOdds = res.L;    res.Max = 'L';  }}int main(){  double MaxPro = 0.0;  for (int i = 0; i < 3; i++)  {    scanf("%lf %lf %lf", &res[i].W, &res[i].T, &res[i].L);    Max3(res[i]);  }  MaxPro = (res[0].MaxOdds*res[1].MaxOdds*res[2].MaxOdds*0.65 - 1) * 2;  printf("%c %c %c %.2f", res[0].Max, res[1].Max, res[2].Max, MaxPro);  return 0;}

version2.0

/*** @tag     PAT_A_1011* @authors R11happy (xushuai100@126.com)* @date    2016-08-10 21:43:16-22:17* @version 1.0* @Language C++* @Ranking  150/4094*/#include <cstdio>#include <cstdlib>#include <cstring>char S[3] = {'W', 'T', 'L'};int main(){    double ans = 1.0, Max, a;    int idx;    //记录每行最大元素的下标    for(int i = 0; i<3; i++)    {        Max = 0.0;        for(int j = 0; j<3; j++)        {            scanf("%lf", &a);            if(a > Max)            {                Max = a;                idx = j;            }        }        ans*=Max;        printf("%c ", S[idx]);    }    printf("%.2f", (ans*0.65-1)*2);    return 0;}

收获:

1.引用传参数的函数调用

void Max3(Game &res)//函数声明Max3(res[i]);;//函数调用

2.

double类型     scanf---%lf    printf---%f
float类型    scanf---%f    printf---%f

3.字符类型用0,1,2……对应起来

char S[3] = {'W', 'T', 'L'};
0 0
原创粉丝点击