PAT甲级 1011 World Cup Betting (20 分)

太过爱你忘了你带给我的痛 2023-06-10 05:30 138阅读 0赞

For example, 3 games’ odds are given as the following:

  1. W T L
  2. 1.1 2.5 1.7
  3. 1.2 3.1 1.6
  4. 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.1 2.5 1.7
  2. 1.2 3.1 1.6
  3. 4.1 1.2 1.1

Sample Output:

  1. T T W 39.31
  2. #include<iostream>
  3. #include<vector>
  4. #include<iomanip>
  5. using namespace std;
  6. int main()
  7. {
  8. float num[5];
  9. float sum=0.65,max;
  10. int index;
  11. char bet[3]={ 'W','T','L'};
  12. for(int i=0;i<3;i++)
  13. {
  14. cin>>num[0]>>num[1]>>num[2];
  15. max=num[0];
  16. index=0;
  17. for(int i=1;i<3;i++)
  18. {
  19. if(num[i]>max)
  20. {
  21. index=i;
  22. max=num[i];
  23. }
  24. }
  25. sum*=max;//乘以最大的数
  26. cout<<bet[index]<<" ";
  27. }
  28. cout<<fixed<<setprecision(2);
  29. cout<<(sum-1)*2;
  30. return 0;
  31. }

发表评论

表情:
评论列表 (有 0 条评论,138人围观)

还没有评论,来说两句吧...

相关阅读