Post

[백준] 9498번 - 시험 성적 [Java][C++]

[백준] 9498번 - 시험 성적 [Java][C++]

문제 링크


1. 문제 풀이

시험 점수를 입력받아 성적을 출력하는 문제로 조건문을 활용하면 해결할 수 있다.


2. 코드

1. 구현 [Java]

if ~ else if ~ else 구문을 활용해서 더 좁은 범위부터 평가했다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int score = Integer.parseInt(br.readLine());

        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");
        }
    }
}

2. 구현 [C++]

if ~ else if ~ else 구문을 활용해서 더 좁은 범위부터 평가했다.

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

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

    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';
    }
}

3. 풀이 정보

1. 구현 [Java]

언어시간메모리코드 길이
Java 11100 ms14248 KB589 B

2. 구현 [C++]

언어시간메모리코드 길이
C++ 170 ms2020 KB389 B

This post is licensed under CC BY 4.0 by the author.