fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main(void)
  6. {
  7. int t;
  8. cin >> t;
  9.  
  10. for(int pk = 1; pk <= t; pk++)
  11. {
  12. double n;
  13. string unit;
  14. cin >> n >> unit;
  15.  
  16. if (unit == "kg")
  17. {
  18. n *= 2.2046;
  19. unit = "lb";
  20. }
  21. else if (unit == "l")
  22. {
  23. n *= 0.2642;
  24. unit = "g";
  25. }
  26. else if (unit == "lb")
  27. {
  28. n *= 0.4536;
  29. unit = "kg";
  30. }
  31. else if (unit == "g")
  32. {
  33. n *= 3.7854;
  34. unit = "l";
  35. }
  36. cout << fixed; //소수점이하 수 출력
  37. cout.precision(4); //4자리까지
  38. cout << pk << " " << n << " " << unit << endl;
  39. }
  40. }
Success #stdin #stdout 0.01s 5692KB
stdin
5
1 kg
2 l
7 lb
3.5 g
0 l
stdout
1 2.2046 lb
2 0.5284 g
3 3.1752 kg
4 13.2489 l
5 0.0000 g