https://school.programmers.co.kr/learn/courses/30/lessons/150368
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
이모티콘 플러스 가입자와 이모티콘 판매액을 비교하여 주어진 기준에 따라 최대한의 목적을 달성한 매출액을 정답으로 제출하는 문제
List와 Queue를 이용, 할인된 가격의 합과 이모티콘 플러스의 가격을 비교하면서 정답을 구했다
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
class Solution {
public int[] solution(int[][] users, int[] emoticons) {
int[] answer = {0, 0};
int[] discountRate = {10, 20, 30, 40};
Queue<List<Integer>> q = new LinkedList<>();
for (int dc : discountRate) {
List<Integer> l = new ArrayList<>();
l.add(dc);
q.add(l);
}
for (int i = 0; i < emoticons.length-1; i++) {
int size = q.size();
for (int j = 0; j < size; j++) {
List<Integer> list = q.poll();
for (int dc : discountRate) {
List<Integer> l = new ArrayList<>(list);
l.add(dc);
q.add(l);
}
}
}
while (!q.isEmpty()) {
List<Integer> l = q.poll();
int emoticonPlus = 0;
int sumPrice = 0;
for (int i = 0; i < users.length; i++) {
int[] user = users[i];
int price = 0;
for (int j = 0; j < l.size(); j++) {
if (l.get(j) >= user[0]) {
price += emoticons[j] * (100 - l.get(j)) / 100;
}
}
if (price >= user[1]) {
emoticonPlus++;
} else {
sumPrice += price;
}
}
if (answer[0] < emoticonPlus) {
answer[0] = emoticonPlus;
answer[1] = sumPrice;
} else if (answer[0] == emoticonPlus && answer[1] < sumPrice) {
answer[1] = sumPrice;
}
}
return answer;
}
}
'Programmers' 카테고리의 다른 글
[프로그래머스][JAVA]Lv. 2 - 마법의 엘리베이터 (0) | 2024.03.18 |
---|---|
[프로그래머스][JAVA]Lv. 2 - 테이블 해시 함수 (0) | 2024.03.11 |
[프로그래머스][JAVA]Lv. 2 - 디펜스 게임 (1) | 2024.02.26 |
[프로그래머스][JAVA]Lv. 2 - 점 찍기 (0) | 2024.02.19 |
[프로그래머스][JAVA]Lv. 2 - 귤 고르기 (0) | 2024.02.19 |