-- 예전 기록/BOJ

[ BOJ ] 9498 : 시험 성적 ( BRONZE 5 ) / C, C++, Python, Java

rejo 2023. 8. 30. 15:50

문제

시험 점수를 입력받아 90 ~ 100점은 A, 80 ~ 89점은 B, 70 ~ 79점은 C, 60 ~ 69점은 D, 나머지 점수는 F를 출력하는 프로그램을 작성하시오.

입력

첫째 줄에 시험 점수가 주어진다. 시험 점수는 0보다 크거나 같고, 100보다 작거나 같은 정수이다.

출력

시험 성적을 출력한다.

풀이 과정

시험 점수에 맞는 등급을 조건문을 이용해 출력한다.

C

#include <stdio.h>

int main(void) {
    int score;
    scanf("%d", &score);

    if (score >= 90) printf("A");
    else if (score >= 80) printf("B");
    else if (score >= 70) printf("C");
    else if (score >= 60) printf("D");
    else printf("F");

    return 0;
}

C++

#include <iostream>
using namespace std;

int main(void) {
    int score; cin >> score;

    if (score >= 90) cout << "A";
    else if (score >= 80) cout << "B";
    else if (score >= 70) cout << "C";
    else if (score >= 60) cout << "D";
    else cout << "F";

    return 0;
}

Python

import sys
input = sys.stdin.readline

score = int(input().rstrip())
print('A' if score >= 90 else ('B' if score >= 80 else ('C' if score >= 70 else ('D' if score >= 60 else 'F'))))

Java

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int score = sc.nextInt();

        if (score >= 90) System.out.println("A");
        else if (score >= 80) System.out.println("B");
        else if (score >= 70) System.out.println("C");
        else if (score >= 60) System.out.println("D");
        else System.out.println("F");
    }
}