반응형

백준 10768번 특별한 날 풀이 코드

C | C++ | Java | Python


풀이

조건문으로 Before, After, Special을 구분합니다.

코드

#include <stdio.h>
int main(){
    int m, d;
    scanf("%d %d", &m, &d);
    if (m < 2)
        printf("Before");
    else if (m == 2){
        if (d < 18)
            printf("Before");
        else if (d > 18)
            printf("After");
        else
            printf("Special");
    }
    else
        printf("After");
    return 0;
}
#include <iostream>
using namespace std;
int main(){
    int m, d;
    cin>>m>>d;
    if (m < 2)
        cout<<"Before";
    else if (m == 2){
        if (d < 18)
            cout<<"Before";
        else if (d > 18)
            cout<<"After";
        else
            cout<<"Special";
    }
    else
        cout<<"After";
    return 0;
}
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt(), d = sc.nextInt();
        if (m < 2)
            System.out.println("Before");
        else if (m == 2){
            if (d < 18)
                System.out.println("Before");
            else if (d > 18)
                System.out.println("After");
            else
                System.out.println("Special");
        }
        else
            System.out.println("After");
    }
}
m = int(input())
d = int(input())
if m < 2:
    print("Before")
elif m == 2:
    if d < 18:
        print("Before")
    elif d > 18:
        print("After")
    else:
        print("Special")
else:
    print("After")

문제 출처

https://www.acmicpc.net/problem/10768

반응형

+ Recent posts