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.1 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.1×2.5×65%−1)×2=39.31 yuans (accurate up to 2 decimal places)(精确到两位小数).
Input Specification:
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 Specification:
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.1 1.6
4.1 1.2 1.1
Sample Output:
T T W 39.31
思路:1.由于输入次数未指定,所以采用while(cin>>a>>b>>c)来无限读取
2.采用vector动态数组,实时添加元素
3.获得三个数中的最大值:可用max函数嵌套:max(a,max(b,c))
4.字符与数字之间有关联,用结构体关联起来
AC代码
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
struct bets
{
double x;
char c;
};
using namespace std;
int main()
{
vector<bets> m;
double a,b,c;
while(cin>>a>>b>>c)
{
if(max(a,max(b,c))==a)
m.push_back({a,'W'});
else if(max(a,max(b,c))==b)
m.push_back({b,'T'});
else if(max(a,max(b,c))==c)
m.push_back({c,'L'});
}
double sum=0.65;
for(int i=0;i<m.size();i++)
{
cout<<m[i].c<<" ";
sum*=m[i].x;
}
cout<<fixed<<setprecision(2)<<(sum-1)*2;
return 0;
}