PAT甲级刷题实录——1011

原题链接

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';
	}
}
原文地址:https://www.cnblogs.com/aopstudio/p/12229533.html