728x90
package prog;
public class 이주차 {
public static void main(String[] args) {
Solution s = new Solution();
//System.out.println(s.solution(new int[][] {{100,90,98,88,65},{50,45,99,85,77},{47,88,95,80,67},{61,57,100,80,65},{24,90,94,75,65}}));
System.out.println(s.solution(new int[][] {{70,49,90},{68,50,38},{73,31,100}}));
}
}
class Solution {
public String solution(int[][] scores) {
String answer = "";
int N = scores.length;
double[] socoreList = new double[N];
for (int i = 0; i < N; i++) {
int myScore = scores[i][i];
int cnt = 0;
int total = 0;
int maxValue = Integer.MIN_VALUE;
int minValue = Integer.MAX_VALUE;
for (int j = 0; j < N; j++) {
if(myScore==scores[j][i]){
cnt++;
}
maxValue = Math.max(maxValue,scores[j][i]);
minValue = Math.min(minValue,scores[j][i]);
total+=scores[j][i];
}
if( (maxValue==myScore ||minValue==myScore) && cnt==1){
total-=myScore;
answer+= checkGrade((double)total/(N-1));
}
else{
answer += checkGrade((double)total/N);
}
}
System.out.println("answer = " + answer);
return answer;
}
private String checkGrade(double score) {
if(score>=90) return "A";
else if(score>=80) return "B";
else if(score>=70) return "C";
else if(score>=50) return "D";
else return "F";
}
}
728x90
'알고리즘 > 프로그래머스' 카테고리의 다른 글
카카오 프렌즈 컬러링북 (0) | 2021.09.03 |
---|---|
직업군 추천하기 (0) | 2021.09.03 |
오픈채팅방 (0) | 2021.09.03 |
문자열 압축 (0) | 2021.09.03 |
프로그래머스 거리두기 확인하기 (0) | 2021.08.30 |