[백준 10768] 특별한 날 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
입력된 날짜가 특정 기준일인 2월 18일과 어떤 관계인지 판별하여 메시지를 출력하는 간단한 조건 분기 문제입니다.
- 입력으로 월(
m
)과 일(d
)이 주어집니다. - 기준일은
2월 18일
입니다. - 다음과 같은 조건에 따라 출력 문자열을 결정합니다:
- 기준일 이전이라면
"Before"
출력 - 기준일과 같다면
"Special"
출력 - 기준일 이후라면
"After"
출력
- 기준일 이전이라면
접근법
- 조건문을 활용하여
월
과일
을 비교합니다.
- 월이
2
보다 작다면 무조건"Before"
- 월이
2
이어도 일이18
보다 작다면"Before"
- 월이
2
이고 일이18
이면"Special"
- 그 외는 모두
"After"
- 월이
- 위 규칙에 맞게 문자열을 출력합니다.
Code
[ C# ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
class Program {
static void Main() {
int m = int.Parse(Console.ReadLine());
int d = int.Parse(Console.ReadLine());
if (m < 2 || (m == 2 && d < 18))
Console.WriteLine("Before");
else if (m == 2 && d == 18)
Console.WriteLine("Special");
else
Console.WriteLine("After");
}
}
[ 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 m, d; cin >> m >> d;
if (m < 2 || (m == 2 && d < 18)) cout << "Before\n";
else if (m == 2 && d == 18) cout << "Special\n";
else cout << "After\n";
return 0;
}