[백준] 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 11 | 100 ms | 14248 KB | 589 B |
2. 구현 [C++]
| 언어 | 시간 | 메모리 | 코드 길이 |
|---|---|---|---|
| C++ 17 | 0 ms | 2020 KB | 389 B |
This post is licensed under CC BY 4.0 by the author.