반응형
https://www.acmicpc.net/problem/11367
11367번: Report Card Time
The input will begin with a single line containing just a whole number, n, of the number of hobbits in the class, followed by n lines in the form a b, where a is the hobbit’s name (only alphabetical characters) and b is the hobbit’s grade, given as a w
www.acmicpc.net
코드
#include <iostream>
using namespace std;
int main() {
int n, score;
string name;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> name >> score;
if (score >= 97) {
cout << name << " A+\n";
}
else if (score >= 90) {
cout << name << " A\n";
}
else if (score >= 87) {
cout << name << " B+\n";
}
else if (score >= 80) {
cout << name << " B\n";
}
else if (score >= 77) {
cout << name << " C+\n";
}
else if (score >= 70) {
cout << name << " C\n";
}
else if (score >= 67) {
cout << name << " D+\n";
}
else if (score >= 60) {
cout << name << " D\n";
}
else {
cout << name << " F\n";
}
}
return 0;
}
풀이
이름과 점수를 입력받아 해당하는 등급을 출력하는 문제이다.
if와 else if문을 사용해 조건에 맞는 등급을 출력하게 한다.
상위 if문에서 97 이상을 출력할 때 하위 else if문에서는 상위 if문의 조건을 제외한 90 이상 97 미만을 조건으로 한다.
반응형
'문제 해결 > BaekJoon' 카테고리의 다른 글
[백준] [C++] 13752번 히스토그램 (0) | 2022.11.18 |
---|---|
[백준] [C++] 11654번 아스키 코드 (0) | 2022.11.18 |
[백준] [C++] 11319번 Count Me In (0) | 2022.11.17 |
[백준] [C++] 11104번 Fridge of your Dreams (0) | 2022.11.17 |
[백준] [C++] 10926번 ??! (0) | 2022.11.17 |