๋ด๊ฐ ์๊ฐํ ์๊ณ ๋ฆฌ์ฆ
๋ด ํ์ด (0.5H)
import java.util.HashMap;
class Solution {
static HashMap<String, String> relationMaps = new HashMap<String, String>();
static HashMap<String, Integer> payMaps = new HashMap<String, Integer>();
public int[] solution(String[] enrolls, String[] referrals, String[] sellers, int[] amounts) {
int[] answer = new int[enrolls.length];
// ๊ด๊ณ Map ํ์์ผ๋ก ๋งคํ
for (int i = 0; i < enrolls.length; i++) {
relationMaps.put(enrolls[i], referrals[i]);
}
// 0์ผ๋ก ์ด๊ธฐํ
for (int i = 0; i < enrolls.length; i++) {
payMaps.put(enrolls[i], 0);
}
// ์์ต ๊ณ์ฐ
for (int i = 0; i < sellers.length; i++) {
getPaid(sellers[i], amounts[i] * 100);
}
for (int i = 0; i < enrolls.length; i++) {
answer[i] = payMaps.get(enrolls[i]);
}
return answer;
}
public void getPaid(String seller, int earns) {
int referralPaid = (int) (earns * 0.1);
int sellerPaid = earns - referralPaid;
payMaps.replace(seller, payMaps.get(seller) + sellerPaid); // debug # 1 : ๋จผ์ ์ง๊ธํด์ผํจ
if (relationMaps.get(seller).equals("-")) {
return;
}
if (referralPaid < 1) {
return;
}
getPaid(relationMaps.get(seller), referralPaid);
}
}
1. debug #1 : ํธ์ถ ์ข ๋ฃ ํ ์ง๊ธ์ด ์๋ ์ง๊ธํ ์ข ๋ฃ ํ์ด์ผํจ
๋ฐ์ํ
'๐ค ์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
baekjoon. ๋ ๊ฒ์ (0) | 2022.08.31 |
---|---|
baekjoon. ๋ฌธ์์ด ํญ๋ฐ (0) | 2022.08.29 |
์๊ณ ๋ฆฌ์ฆ ๊ฟํ. ์๋ฐ (0) | 2022.06.27 |
programmers. ํ๋ ฌ ํ ๋๋ฆฌ ํ์ ํ๊ธฐ (0) | 2022.06.26 |
programmers. ๋ก๋์ ์ต๊ณ ์์์ ์ต์ ์์ (0) | 2022.06.23 |