https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AW45RuSae2gDFAQ7&categoryId=AW45RuSae2gDFAQ7&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=JAVA&select-1=3&pageSize=10&pageIndex=5
조건
- 문제 배점 표 먼저 구하기
- 배점표를 이용해 Collections.sort, Comparable 이용하기 위해 Person 클래스 생성 및 빠른 정렬을 위해 LinkedList 사용
public class Pro8888 {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int TC = Integer.parseInt(br.readLine());
for(int T=1;T<=TC;T++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int t = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
int[][] arr = new int[n][t];
int[] score = new int[t];
for(int i=0;i<n;i++) {
st = new StringTokenizer(br.readLine());
for(int j=0;j<t;j++) {
arr[i][j]=Integer.parseInt(st.nextToken());
}
}
//문제 배점 구하기
for(int i=0;i<t;i++) {
int count = 0;
for(int j=0;j<n;j++) {
if(arr[j][i]==1)count++;
}
score[i]=n-count;
}
List<Person> personList = new LinkedList<>();
for(int i=0;i<n;i++) {
int count = 0;
int value = 0;
for(int j=0;j<t;j++) {
if(arr[i][j]==1) {
count++;
value+=score[j];
}
}
personList.add(new Person(i+1,count,value));
}
Collections.sort(personList);
Person tmp=null;
int rank = 0;
for(int i=0;i<personList.size();i++) {
if(personList.get(i).index==p) {
rank=i+1;
tmp = personList.get(i);
}
}
bw.write("#"+T+" "+tmp.value+" "+rank+"\n");
}
bw.flush();
bw.close();
}
}
class Person implements Comparable<Person>{
int index;
int count;
int value;
public Person(int index, int count, int value) {
this.index = index;
this.count = count;
this.value = value;
}
@Override
public int compareTo(Person o) {
if(this.value==o.value) {
if(this.count==o.count) {
return this.index - o.index;
}else return o.count - this.count;
}else return o.value - this.value;
}
}