※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 14013번 문제인 Unit Conversion이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/14013
14013번: Unit Conversion
The input will begin with a line containing 2 numbers x and y meaning that "x of unit A" is equal to "y of unit B". For instance, if A is "kilos" and B is "pounds" one possibility is x = 3.25 and y = 7.165024. The next line will contain a single integer N,
www.acmicpc.net
단위의 변환을 물어보는 문제이다.
양의 실수 x와 y에 대하여 x A와 y B가 같다는 것은 1 A당 (y/x) B와 같고, 1 B당 (x/y)와 같다는 의미이다 (단 /는 실수의 나눗셈이다).
이를 이용해 주어지는 실수와 단위를 입력받아 다른 단위로 변환해 출력해주자.
아래는 제출한 소스코드이다.
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed;
cout.precision(10);
double x, y; cin >> x >> y;
int T; cin >> T;
while (T--) {
double k; char c; cin >> k >> c;
if (c == 'A') cout << k * y / x << '\n';
else cout << k * x / y << '\n';
}
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 5013 // C++] Death Knight Hero (0) | 2022.05.15 |
---|---|
[BOJ 1774 // C++] 우주신과의 교감 (0) | 2022.05.15 |
[BOJ 14935 // C++] FA (0) | 2022.05.15 |
[BOJ 5558 // C++] チーズ (Cheese) (0) | 2022.05.15 |
[BOJ 3023 // C++] 마술사 이민혁 (0) | 2022.05.15 |