import java.util.*;
class Solution {
static StringBuilder sb = new StringBuilder();
public String solution(int[][] scores) {
int people = scores.length;
for (int i = 0; i < people; i++) {
int myPoint = scores[i][i];
int totalPoint = 0;
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
// 내가 평가받은 점수 계산
for (int j = 0; j < people; j++) {
int point = scores[j][i];
totalPoint += point;
max = Math.max(max, point);
min = Math.min(min, point);
}
int minCount = 0;
int maxCount = 0;
for (int j = 0; j < people; j++) {
int point = scores[j][i];
if (point == min) {
minCount++;
}
if (point == max) {
maxCount++;
}
}
boolean flag = false;
if (myPoint == min && minCount == 1) {
totalPoint -= myPoint;
flag = true;
}
if (myPoint == max && maxCount == 1) {
totalPoint -= myPoint;
flag = true;
}
int avg = 0;
if (flag) {
avg = totalPoint / (people - 1);
} else {
avg = totalPoint / people;
}
getGrade(avg/10);
}
return sb.toString();
}
private void getGrade(int avg) {
char grade;
switch (avg) {
case 10:
case 9:
grade = 'A';
break;
case 8:
grade = 'B';
break;
case 7:
grade = 'C';
break;
case 6:
case 5:
grade = 'D';
break;
default:
grade = 'F';
}
sb.append(grade);
}
}