SWEA_1983) 조교의 성적 매기기

1983) 조교의 성적 매기기 (19.10.04)


문제 링크 (SW Expert Academy)

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.*;
import java.util.*;

class Pair implements Comparable<Pair>{
    int x;
    double y;
    Pair(int x, double y){
        this.x = x;
        this.y = y;
    }
    
    double getScore() {
        return y;
    }
    
    @Override
    public int compareTo(Pair i) {
        double targetScore = i.getScore();
        if(this.y == targetScore) return 0;
        else if(this.y>targetScore) return 1;
        else return -1;
    }
}

public class Solution {
    public static String[] score = {"A+""A0""A-""B+""B0""B-""C+""C0""C-""D0"};
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer tk;
        
        int t = Integer.parseInt(br.readLine());
    
        for(int i=1;i<=t;i++) {
            tk = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(tk.nextToken());
            int k = Integer.parseInt(tk.nextToken());
            
            ArrayList<Pair> list = new ArrayList<Pair>();
            for(int j=0;j<n;j++) {
                tk = new StringTokenizer(br.readLine());
                
                double mid = Integer.parseInt(tk.nextToken()) * 0.35;
                double fin = Integer.parseInt(tk.nextToken()) * 0.45;
                double ass = Integer.parseInt(tk.nextToken()) * 0.2;
                
                double sum = mid+fin+ass;
                
                list.add(new Pair(j+1, sum));
            }
            
            list.sort(Comparator.reverseOrder());
            
            int cnt = 0;
            for(int v=0;v<list.size();v++) {
                Pair p = list.get(v);
                
                if(p.x==k) {
                    cnt = v;
                    break;
                }
            }
            
            n = n/10;
            bw.write("#" + i + " " + score[cnt/n]+"\n");
        }
        
        bw.flush();
        bw.close();
    }
}
cs



* Pair 로 list 만들었을 때 Pair중에 값 하나로 정렬하는거 궁금했었는데
* 이번에 찾아보고 사용해봤다.

* 참고 : https://manorgass.tistory.com/60

댓글

이 블로그의 인기 게시물