[PAT] 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 wocould be the product of the three odds times 65%. for example, 3 games 'odds are given as the following: w t L1.1 2.5 1.71.2 3.0 1.64.1 1.2 1.1To 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 wocould be (4.1*3.0*2.5 * 65%-1) * 2 = 37.98 yuans (accurate up to 2 decimal places ). inputEach 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. outputFor 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 Input1.1 2.5 1.71.2 3.0 1.64.1 1.2 1.1 Sample OutputT t w 37.98 *************************** * ***********************************/# include
# Include
# Include
# Include
Using namespace std; // defines the struct odd {char s; double num; // constructor odd (char s, double num): s (s), num (num) {} // reload
<号bool operator<(odd const &r) const{return num>
R. num ;}; int main () {double sum = 1; // The set element cannot be repeated, and the set element can be repeated.
Myset; myset. clear (); char fag [3]; for (int I = 0; I <3; I ++) {double w, t, l; cin> w> t> l; myset. insert (odd ('w', W); myset. insert (odd ('T', T); myset. insert (odd ('l', L); cout <
S <"; sum * = myset. begin ()-> num; // remember to clear myset every time set. clear ();} sum = (sum * 0.65-1) * 2; printf ("%. 2lf \ n ", sum); return 0 ;} /*************************************** * ********************* method 2 *************** **************************************** * ********/# include
# Include
# Include
Using namespace std; void out (int f) {if (f = 0) cout <"W"; else if (f = 1) cout <"T "; elsecout <"L";} int main () {double num [3] [3]; int I, j; // first save the data to a 2-dimensional array for (I = 0; I <3; I ++) {for (j = 0; j <3; j ++) cin> num [I] [j];} int flag; double result = 1; // find the maximum value for (I = 0; I <3; I ++) {double max =-1; flag = 0; for (j = 0; j <3; j ++) {if (max