Sicily 1511. Conversions

来源:互联网 发布:免费下载源码的网站 编辑:程序博客网 时间:2024/06/09 20:37
    
Time Limit: 1sec    Memory Limit:32MB
Description

Conversion between the metric and English measurement systems is relatively simple. Often, it involves either multiplying or dividing by a constant. You must write a program that converts between the following units:

 

TypeMetricEnglish equivalentWeight1.000 kilograms2.2046 pounds 0.4536 kilograms1.0000 poundVolume1.0000 liter0.2642 gallons 3.7854 liters1.0000 gallon
Input

The first line of input contains a single integer N , (1≤N≤1000) which is the number of datasets that follow.

Each dataset consists of a single line of input containing a floating point (double precision) number, a space and the unit specification for the measurement to be converted. The unit specification is one of kglbl, or g referring to kilograms, pounds, liters and gallons respectively.

Output

For each dataset, you should generate one line of output with the following values: The dataset number as a decimal integer (start counting at one), a space, and the appropriately converted value rounded to 4 decimal places, a space and the unit specification for the converted value.

Sample Input
 Copy sample input to clipboard
5 1 kg 2 l 7 lb 3.5 g 0 l
Sample Output
1 2.2046 lb 2 0.5284 g 3 3.1752 kg 4 13.2489 l 5 0.0000 g

Problem Source: Greater New York 2007


// Problem#: 1511// Submission#: 3685288// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include<iostream>#include<iomanip>#include<string>using namespace std;int main(){    int n;    cin>>n;    int i=1;    while(n--){        //int i=1;        double a;        string b;        cin>>a>>b;        if(b=="kg"){            cout<<i<<" "<<fixed<<setprecision(4)<<a*2.2046<<" lb"<<endl;        }        else if(b=="l"){            cout<<i<<" "<<fixed<<setprecision(4)<<a*0.2642<<" g"<<endl;        }        else if(b=="lb"){            cout<<i<<" "<<fixed<<setprecision(4)<<a*0.4536<<" kg"<<endl;        }        else if(b=="g"){            cout<<i<<" "<<fixed<<setprecision(4)<<a*3.7854<<" l"<<endl;        }        i++;            }    return 0;}                                 


0 0
原创粉丝点击