1011 World Cup Betting (20分)

题目链接: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.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

解题思路:

  • 有一个需要注意的点:题目说了是"Triple Winning" game,所以输入的数据只有三行……这一点我一开始没有注意到=.=
  • 将三组数据依次输入存储到数组后,获取每一行的最大值以及其对应在数组中的下标,最后计算 sum =(max1max2max3*0.65-1) *2即可
    代码如下:
#include
float getMax(float m, float n , float t, int &cnt)
{
	float input[3] = {m,n,t};
	float maxNum = -100;
	cnt = 0;
	for(int i=0; i<3; i++)
	{
		if(input[i] > maxNum){
			maxNum = input[i];
			cnt = i;
		}
	}
	return maxNum;
}
int main()
{
	float input[3][3], maxNum[3];	//	max[3]:记录最大值是多少 
	int cnt[3] = {0};	//	记录最大值对应的ID
	int temp = 0;
	 
	for(int i=0; i<3; i++)
	{
		scanf("%f %f %f", &input[i][0], &input[i][1], &input[i][2]);
	}

	for(int i=0; i<3; i++)
	{
		maxNum[i] = getMax(input[i][0],input[i][1],input[i][2], temp);
		cnt[i] = temp; 
	}
	
	float sum = (maxNum[0] * maxNum[1] * maxNum[2] *0.65 -1)*2;
	for(int i=0; i<3; i++)
	{
		switch(cnt[i])
		{
			case 0:
				printf("W ");
				break;
			case 1:
				printf("T ");
				break;
			case 2:
				printf("L ");
				break;
		}
	}
	printf("%.2f", sum); 
	return 0;
}

你可能感兴趣的:(C/C++)