작성일 :

문제 링크

30793번 - gahui and sousenkyo 3

설명

예선 득표수와 본선 득표수가 주어질 때, 비율에 따라 캐릭터 타입을 출력하는 문제입니다.


접근법

먼저 예선 득표수를 본선 득표수로 나누어 비율을 계산합니다.

이후 비율이 0.2 미만이면 weak, 0.4 미만이면 normal, 0.6 미만이면 strong, 그 이상이면 very strong을 출력합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;

class Program {
  static void Main() {
    var parts = Console.ReadLine()!.Split();
    var p = double.Parse(parts[0]);
    var r = double.Parse(parts[1]);
    var v = p / r;

    var ans = "";
    if (v < 0.2) ans = "weak";
    else if (v < 0.4) ans = "normal";
    else if (v < 0.6) ans = "strong";
    else ans = "very strong";

    Console.WriteLine(ans);
  }
}

C++

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

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

  double p, r; cin >> p >> r;
  double v = p / r;

  if (v < 0.2) cout << "weak\n";
  else if (v < 0.4) cout << "normal\n";
  else if (v < 0.6) cout << "strong\n";
  else cout << "very strong\n";

  return 0;
}