본문 바로가기

Algorithm/Implementation

(C++) - 백준(BOJ) 4714 : Lunacy

반응형

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

 

4714번: Lunacy

After several months struggling with a diet, Jack has become obsessed with the idea of weighing less. In an odd way, he finds it very comforting to think that, if he had simply had the luck to be born on a different planet, his weight could be considerably

www.acmicpc.net

간단한 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

 1. while loop를 수행합니다.  2. 지역변수 x를 선언 후 입력받습니다. x가 음수면 break합니다.

📔 정답출력

형식에 맞게 출력해줍니다.


📕 Code

#include <bits/stdc++.h>
using namespace std;

int main(){
    while(1){
        double x;
        cin >> x;
        if(x < 0) break;
        printf("Objects weighing %.2f on Earth will weigh %.2f on the moon.\n", x, x * 0.167);
    }
}