코딩로그
[백준/BOJ/C++] 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 less.
Of course, the planets are far out of reach, but even the Earth’s moon would yield a dramatic weight loss. Objects on the moon weight only 0.167 of their weight on Earth.
[입력]
Input consists of one or more lines, each containing a single floating point number denoting a weight (in pounds) on the Earth. The end of input is denoted by a negative floating point number.
[출력]
For each line of input data, your program should print a single line of the form
Objects weighing X on Earth will weigh Y on the moon.
where X is the weight from the input and Y is the corresponding weight on the moon. Both output numbers should be printed to a precision of 2 digits after the decimal point.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main() {
while(true){
double input;
cin >> input;
if(input == -1) break;
cout << "Objects weighing ";
printf("%.2f", input);
cout <<" on Earth will weigh ";
printf("%.2f", input * 0.167);
cout << " on the moon.\n";
}
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 7595번 Triangles (0) | 2021.12.22 |
---|---|
[백준/BOJ/C++] 7596번 MP3 Songs (0) | 2021.12.22 |
[백준/BOJ/C++] 13772번 Holes (0) | 2021.12.22 |
[백준/BOJ/C++] 14182번 Tax (0) | 2021.12.22 |
[백준/BOJ/C++] 10804번 카드 역배치 (0) | 2021.12.22 |