사자자리
[C언어] 백준 2755번: 이번학기 평점은 몇점? 본문
https://www.acmicpc.net/problem/2755
2755번: 이번학기 평점은 몇점?
첫째 줄에, 백준이가 이번 학기에 들은 과목 수가 주어진다. 둘째 줄부터 N개의 줄에 각 과목의 과목명, 학점, 성적이 주어진다. 과목명은 알파벳 소문자와 숫자, 그리고 밑줄 (_)로만 이루어져 있
www.acmicpc.net
#include <stdio.h>
double getGrade(char *grade){
double result;
if (grade[0] == 'A') result = 4.0;
else if (grade[0] == 'B') result = 3.0;
else if (grade[0] == 'C') result = 2.0;
else if (grade[0] == 'D') result = 1.0;
else if (grade[0] == 'F') result = 0.0;
if (grade[1] == '+') result += 0.3;
else if (grade[1] == '-') result -= 0.3;
return result;
}
int main(){
int n, credit_sum = 0;
double grade_sum = 0.0, total;
scanf("%d", &n);
for (int i = 0; i < n; i++){
char name[101], grade[3];
int credit;
scanf("%s %d %s", name, &credit, grade);
credit_sum += credit;
grade_sum += credit * getGrade(grade);
}
total = grade_sum/credit_sum + 0.0000001;
printf("%.2f", total);
return 0;
}
'C언어 > C언어 문제' 카테고리의 다른 글
[C언어] 백준 1259번: 팰린드롬수 (0) | 2022.07.24 |
---|---|
[C언어] 백준 1547번: 공 (0) | 2022.07.15 |
[C언어] 백준 1236번: 성 지키기 (0) | 2022.07.14 |
[C언어] 백준 1145번: 적어도 대부분의 배수 (0) | 2022.07.14 |
[C언어] 백준 1110번: 더하기 사이클 (0) | 2022.07.10 |
Comments