티스토리 뷰

1주차 

1
2
3
4
5
6
7
8
9
10
11
12
class 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주차

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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);
    }
}
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