PAT A 1011 World Cup Betting

With the 2010 FIFA World Cup running, football fans the world over werebecoming increasingly excited as the best players from the best teamsdoing 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 ofwinning was simple: first select any three of the games. Then for eachselected game, bet on one of the three possible results -- namely W forwin, T for tie, and L for lose. There was an odd assigned to eachresult. The winner's odd would be the product of the three odds times65%.

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 the2nd game, and T for the 1st game. If each bet takes 2 yuans, then themaximum 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 bettinginformation of 3 games. Each game occupies a line with three distinctodds corresponding to W, T and L.

Output

For each test case, print in one line the best bet of each game, and themaximum profit accurate up to 2 decimal places. The characters and thenumber 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
#include<cstdio>    //为什么运行会出问题。。。

int main() {
	double a[5] = { 0 };
	double a1, a2, a3;
	char b[4] = { 'W','T','L' };
	int k = 0;
	for (int i = 0; i < 3; i++) {
		scanf("%lf %lf %lf", &a[i]);
		if (a[i] > a[k]) k = i;
	}
	a1 = a[k];
	printf("%c ", b[k]);

	k = 0;
	for (int i = 0; i < 3; i++) {
		scanf("%lf %lf %lf", &a[i]);
		if (a[i] > a[k]) k = i;
	}
	a2 = a[k];
	printf("%c ", b[k]);

	k = 0;
	for (int i = 0; i < 3; i++) {
		scanf("%lf %lf %lf", &a[i]);
		if (a[i] > a[k]) k = i;
	}
	a3 = a[k];
	printf("%c ", b[k]);

	printf("%.2f", (a1*a2*a3*0.65 - 1) * 2);
	return 0;
}

晴神代码

#include<cstdio>
int main() {
    double ans = 1.0, temp, a;
    int p[3] = { 0 };
    int id;        //id为每三个数据的最大值的下标,存在数组里,后面一起输出,这样输出才在同一行
    char b[4] = { 'W','T','L' };
    for (int i = 0; i < 3; i++) {
        temp = 0;
        for (int j = 0; j < 3; j++) {
            scanf("%lf", &a);
            if (a > temp) temp = a, id = j;
        }
        p[i] = id;
        ans *= temp;
    }
    printf("%c %c %c ", b[p[0]], b[p[1]], b[p[2]]);
    printf("%.2f", (ans*0.65 - 1) * 2);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/joah_ge/article/details/80547734