코테/백준

[백준/JAVA] 2755번: 이번학기 평점은 몇점?

imname1am 2023. 6. 9. 15:01
반응형

🔺 문제

 

2755번: 이번학기 평점은 몇점?

첫째 줄에, 백준이가 이번 학기에 들은 과목 수가 주어진다. 둘째 줄부터 N개의 줄에 각 과목의 과목명, 학점, 성적이 주어진다. 과목명은 알파벳 소문자와 숫자, 그리고 밑줄 (_)로만 이루어져 있

www.acmicpc.net

 

 

🔺 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        
        HashMap<String, Double> map = new HashMap<>();
        map.put("A+"4.3); map.put("A0"4.0); map.put("A-"3.7);
        map.put("B+"3.3); map.put("B0"3.0); map.put("B-"2.7);
        map.put("C+"2.3); map.put("C0"2.0); map.put("C-"1.7);
        map.put("D+"1.3); map.put("D0"1.0); map.put("D-"0.7);
        map.put("F"0.0);
        
        double hak = 0;    // 학점
        double pyung = 0;  // 평점
        
        int N = Integer.parseInt(br.readLine());
        while(N --> 0) {
            String[] str = br.readLine().split(" ");
            
            hak += Integer.parseInt(str[1]);
            pyung += Integer.parseInt(str[1]) * map.get(str[2]);  // 평점 : 학점 * 성적
        }
        
        System.out.printf("%.2f", pyung / hak);
    }
}
cs
✅ 해결 아이디어
✔ HashMap에 성적과 그에 따른 평점을 넣었다.

 


🔺 다른 풀이들

 

로그인

 

www.acmicpc.net

 

 

로그인

 

www.acmicpc.net


💬 느낀 점

규칙 찾아서 구현하면 되는디 그냥 귀찮아서 Map 썼다,,,

 

1회독 2회독 3회독 4회독 5회독
V        
반응형