2031 - P316 3

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

P316 3

题目输入

类型 数量 长 宽 高

类型 数量 长 宽 高

类型 数量 长 宽 高

T

题目输出

总价

输入/输出样例

输入格式

P 10 2 4 8
M 1 1 12 8
T

输出格式

83.47

C++解答

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>

using namespace std;

float cost(char, int, int, int, int);

int main()
{
	char wood = ' ';
	int quantity, width, height, length;
	string fullname;
	float total = 0.00;

	while(cin && wood!='T')
	{
		cin >> wood;
		if(wood=='T')
			break;
		else if(wood=='P' || wood=='F' || wood=='C' || wood=='M' || wood=='O')
		{
			cin >> quantity >> width >> height >> length;
			switch(wood)
			{
			case 'P':
				fullname = "Pine";
				break;
			case 'F':
				fullname = "Fir";
				break;
			case 'C':
				fullname = "Cedar";
				break;
			case 'M':
				fullname = "Maple";
				break;
			case 'O':
				fullname = "Oak";
				break;
			}
		
			total += cost(wood, quantity, width, height, length);
		}
	}

	cout << fixed << setprecision(2) << total <<endl;

	return 0;
}

float cost(char n, int quantity, int width, int height, int length)
{
	float unit;
	switch(n)
	{
	case 'P':
		unit = 0.89;
		break;
	case 'F':
		unit = 1.09;
		break;
	case 'C':
		unit = 2.26;
		break;
	case 'M':
		unit = 4.50;
		break;
	case 'O':
		unit = 3.10;
		break;
	}
	float cost;
	cost = unit * quantity * (width * height * length / 12.000);
	
	return cost;
}