작성일 :

문제 링크

4714번 - Lunacy

설명

지구 체중을 달 체중으로 환산하는 문제입니다.


접근법

달에서의 체중은 지구의 0.167배입니다.

음수가 입력되면 종료하고, 그 외에는 환산 결과를 소수 둘째 자리까지 출력합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
using System;

class Program {
  static void Main() {
    while (true) {
      if (!double.TryParse(Console.ReadLine(), out var w)) break;
      if (w < 0) break;
      var moon = w * 0.167;
      Console.WriteLine("Objects weighing {0:F2} on Earth will weigh {1:F2} on the moon.", w, moon);
    }
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  double w;
  while (cin >> w) {
    if (w < 0) break;
    double moon = w * 0.167;
    cout.setf(ios::fixed);
    cout.precision(2);
    cout << "Objects weighing " << w << " on Earth will weigh " << moon << " on the moon." << "\n";
  }

  return 0;
}