[백준 20673] Covid-19 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
최근 2주 평균 신규 확진 수 p (백만 명당)와 신규 입원 수 q (0 ≤ q ≤ p ≤ 1000)가 주어지는 상황에서, 정해진 기준에 따라 White, Yellow, Red 중 하나를 출력하는 문제입니다.
접근법
주어진 p와 q 값을 기준에 따라 분류하면 됩니다.
기준은 다음과 같습니다:
- p ≤ 50이고 q ≤ 10인 경우: White
- q > 30인 경우: Red
- 그 외의 경우: Yellow
조건을 확인하는 순서가 중요합니다. White 조건은 두 개의 조건을 모두 만족해야 하고, Red 조건은 q만 확인하면 됩니다.
조건문을 순서대로 확인하여 첫 번째로 만족하는 조건의 결과를 출력합니다.
Code
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System;
namespace Solution {
class Program {
static void Main(string[] args) {
var p = int.Parse(Console.ReadLine()!);
var q = int.Parse(Console.ReadLine()!);
if (p <= 50 && q <= 10) Console.WriteLine("White");
else if (q > 30) Console.WriteLine("Red");
else Console.WriteLine("Yellow");
}
}
}
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int p, q; cin >> p >> q;
if (p <= 50 && q <= 10) cout << "White\n";
else if (q > 30) cout << "Red\n";
else cout << "Yellow\n";
return 0;
}