반응형
https://www.acmicpc.net/problem/2712
간단 구현문제였습니다.
📕 풀이방법
📔 입력 및 초기화
testcase t, 무게 weight, 단위 unit을 선언 후 입력받습니다.
📔 풀이과정
표에 나와 있는 데로 단위를 바꾸고 환산한 값을 반환하는 getConvertedWeight함수를 수행합니다.
📔 정답출력
함수 수행 결과를 소수점 4째자리까지 출력하고 단위를 출력합니다.
📕 Code
#include <bits/stdc++.h>
using namespace std;
double t, weight;
string unit;
double getConvertedWeight(){
if(unit == "kg") {
unit = "lb";
return weight * 2.2046;
}
if(unit == "lb"){
unit = "kg";
return weight * 0.4536;
}
if(unit == "l") {
unit = "g";
return weight * 0.2642;
}
unit = "l";
return weight * 3.7854;
}
int main(){
cin >> t;
while(t--){
cin >> weight >> unit;
printf("%.4f", getConvertedWeight());
cout << " " << unit << '\n';
}
}
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++) - 백준(BOJ) 4696 : St. lves (0) | 2022.07.29 |
---|---|
(C++) - 백준(BOJ) 3512 : Flat (0) | 2022.07.28 |
(C++) - 백준(BOJ) 24724번 : 현대모비스와 함께하는 부품 관리 (0) | 2022.07.26 |
(C++) - 백준(BOJ) 10698 번 : Ahmed Aly (0) | 2022.07.25 |
(C++) - 백준(BOJ) 25377 번 : 빵 (0) | 2022.07.22 |