码迷,mamicode.com
首页 > 其他好文 > 详细

PAT甲级刷题实录——1011

时间:2020-01-22 22:06:31      阅读:50      评论:0      收藏:0      [点我收藏+]

标签:vector   int   根据   print   stream   ble   clu   cpp   http   

原题链接

https://pintia.cn/problem-sets/994805342720868352/problems/994805504927186944

思路

这题就很简单了,每行输入的时候找出最大的记录下来,同时记录下标。输入完毕后根据下标转换成结果(W,T,L)并储存起来,再根据每行的最大值计算profit。最后输出结果和profit即可,代码如下。

代码

#include <iostream>
#include <vector>
using namespace std;
char transfer(int j);
int main()
{
    double maxNums[3];
    char results[3];
    double profit;
    for (int i = 0; i < 3; i++)
    {
        double max = 0.0, num;
        for (int j = 0; j < 3; j++)
        {
            cin >> num;
            if (num > max)
            {
                max = num;
                results[i] = transfer(j);
            }
        }
        maxNums[i] = max;
    }
    profit = (maxNums[0] * maxNums[1] * maxNums[2] * 0.65 - 1) * 2;
    for (int i = 0; i < 3; i++)
        cout << results[i] << ' ';
    printf("%.2lf", profit);
}
char transfer(int j)
{
    switch (j)
    {
    case 0:
        return 'W';
    case 1:
        return 'T';
    case 2:
        return 'L';
    }
}

PAT甲级刷题实录——1011

标签:vector   int   根据   print   stream   ble   clu   cpp   http   

原文地址:https://www.cnblogs.com/aopstudio/p/12229533.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!