안녕하세요. 오늘은 미국 스타일을 알아볼 거예요.

문제

https://www.acmicpc.net/problem/2712

아이디어

그냥 뒤에 나오는 단위에 따라서 네가지로 분류한 뒤 적당히 곱해서 출력해주면 됩니다.

소스코드

#include <iostream>
#include <string>
#define ll long long
using namespace std;

int main(void)
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll N, i;
    double x;
    string s;

    cin >> N;

    cout.precision(4); cout << fixed;
    for (i = 0; i < N; i++)
    {
        cin >> x >> s;
        if (s == "kg") cout << x * 2.2046 << " lb\n";
        if (s == "lb") cout << x * 0.4536 << " kg\n";
        if (s == "l") cout << x * 0.2642 << " g\n";
        if (s == "g") cout << x * 3.7854 << " l\n";
    }
}


감사합니다.

0개의 댓글