import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class Solution {
static String[] score = {"A+", "A0", "A-",
"B+", "B0", "B-", "C+", "C0", "C-", "D"};
public static void main(String[] args) throws Exception {
System.setIn(new FileInputStream("./sw1983/input1983.txt"));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringTokenizer st;
for (int test_case = 1; test_case <= T; test_case++) {
st = new StringTokenizer(br.readLine());
int allNum = Integer.parseInt(st.nextToken());
int studentNum = Integer.parseInt(st.nextToken());
List<Double> grade = new ArrayList<>();
double studentScore = 0.0;
for (int i = 0; i < allNum; i++) {
st = new StringTokenizer(br.readLine());
double midterm = Integer.parseInt(st.nextToken());
double finals = Integer.parseInt(st.nextToken());
double project = Integer.parseInt(st.nextToken());
double sum = midterm * 0.35 + finals * 0.45 + project * 0.2;
grade.add(sum);
if (i + 1 == studentNum) studentScore = grade.get(i);
}
Collections.sort(grade, Collections.reverseOrder());
int index = 0;
for (int i = 0; i < grade.size(); i++) {
if (grade.get(i) == studentScore) {
index = i;
}
}
index = index / (allNum / 10);
System.out.printf("#%d %s\n", test_case, score[index]);
}
}
}
✅ 키워드
index를 잘 활용할 것
정해진 성적은 enum 배열처럼 하나 생성해둘 것
오름차순, 내림차순 정렬
// 오름차순으로 정렬
Collections.sort(list);
System.out.println("오름차순 : " + list);
// [A, B, C, a]
// 내림차순으로 정렬
Collections.sort(list, Collections.reverseOrder());
System.out.println("내림차순 : " + list);
// [a, C, B, A]
// 대소문자 구분없이 오름차순
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
System.out.println("대소문자 구분없이 오름차순 : " + list);
// [a, A, B, C]
// 대소문자 구분없이 내림차순
Collections.sort(list, Collections.reverseOrder(String.CASE_INSENSITIVE_ORDER));
System.out.println("대소문자 구분없이 내림차순 : " + list);
// [C, B, a, A]