-
프로그래머스 위클리 챌린지PS/programmers 2021. 8. 11. 15:13
1주차
123456789101112class Solution {public long solution(int price, int money, int count) {long totalPrice = 0;for(int i = 1; i <= count; i++) {totalPrice += (price * i);}long result = money - totalPrice;return result > 0 ? 0 : -result;}}cs
2주차
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980import 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);}}cs 'PS > programmers' 카테고리의 다른 글
MySQL 3레벨 다 풀었다. (0) 2021.08.15 MySQL 2레벨 다 풀었다. (0) 2021.08.06 MySQL 1레벨 다 풀었다. (0) 2021.08.06 Level2) 카펫 (0) 2021.07.13 Level2) H-Index (0) 2021.05.04