zoj 2988 Conversions

//单位之间的转换,用一个map映射器就很容易解决!
#include "iostream"
#include "string"
#include "map"
#include "iomanip"
using namespace std;

int main()
{
	int testcase, count = 0;
	double n, ans;
	string measurement;
	map<string, double>m;
	map<string, string>m1;
	m["kg"] = 2.2046, m["lb"] = 0.4536, m["l"] = 0.2642, m["g"] = 3.7854;
	m1["kg"] = "lb", m1["l"] = "g", m1["lb"] = "kg", m1["g"] = "l";
	cin >> testcase;
	while (testcase--)
	{
		cin >> n >> measurement;
		count++;
		ans = n * m[measurement];
		cout.setf(ios::fixed);
		cout << count << " " << setprecision(4) << ans << " " << m1[measurement] << endl;
	}
}

你可能感兴趣的:(ios)