1 条题解

  • 0
    @ 2024-12-24 9:49:25

    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;
    }
    
    • 1

    信息

    ID
    970
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者