PAT甲级 1011 World Cup Betting

1011 World Cup Betting (20)(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

题意要求:

扫描二维码关注公众号,回复: 2167955 查看本文章

先输出三行各自选择的是W、T、L中的哪一个,然后根据计算公式 (a * b * c * 0.65 – 1) * 2 得出最大收益。

方法一(简洁版):

#include <stdio.h>
#include <iostream>
using namespace std;

int main() {
	float res = 1;
	char ch[] = "WTL";
	for(int i=0;i<3;i++){
		float maxval = -1;
		int k = 0;
		for(int j=0;j<3;j++)
		{
			float val;
			cin>>val;
			if(maxval < val){
				maxval = val;
				k = j;
			}
				
		}
		res *= maxval;
		cout<<ch[k]<<" ";//可以直接打印 
	}
	
	printf("%.2f",(res*0.65 - 1)*2);
	
	
	return 0;
}

方法二:

#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	float a,b,c;
	float a_max=-1,b_max=-1,c_max=-1;
	
	int i,j,k = 0;
	cin>>a>>b>>c;
	if(a >= b && a >= c){
		i = 1;
		a_max = a;
	}
	
	else if(b >= a && b >= c){
		i = 2;
		a_max = b;
	}
	else
	{
		i = 3;
		cout<<"L";
	}
	
	cin>>a>>b>>c;
	if(a >= b && a >= c){
		j = 1;
		b_max = a;
	}
	
	else if(b >= a && b >= c){
		j = 2;
		b_max = b;
	}
	else
	{
		j = 3;
		b_max = c;
	}
	
	cin>>a>>b>>c;
	if(a >= b && a >= c){
		k = 1;
		c_max = a;
	}
	
	else if(b >= a && b >= c){
		k = 2;
		c_max = b;
	}
	else
	{
		k = 3;
		c_max = c;
	}
	
	if(i == 1)
		cout<<"W";
	else if(i == 2)
		cout<<"T";
	else
		cout<<"L"; 
		
	if(j == 1)
		cout<<" W";
	else if(j == 2)
		cout<<" T";
	else
		cout<<" L"; 
		
	if(k == 1)
		cout<<" W";
	else if(k == 2)
		cout<<" T";
	else
		cout<<" L"; 
	
	printf(" %.2f",(a_max*b_max*c_max*0.65 - 1)*2);
	
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_29762941/article/details/81007961