https://programmers.co.kr/learn/courses/30/lessons/77486?language=cpp
#include <string>
#include <vector>
#include <map>
using namespace std;
map<string,string> parent;
map<string,int> profit;
void MakeProfit(string name,int money){
if(name == "-") return;
int give = money * 0.1;
profit[name] = profit[name] + (money-give);
if(give <1) return;
MakeProfit(parent[name],give);
}
vector<int> solution(vector<string> enroll, vector<string> referral, vector<string> seller, vector<int> amount) {
vector<int> answer;
for(int i=0; i<enroll.size(); i++){
parent[enroll[i]] = referral[i];
}
for(int i=0; i<seller.size(); i++){
MakeProfit(seller[i],amount[i]*100);
}
for(int i=0; i<enroll.size(); i++){
answer.push_back(profit[enroll[i]]);
}
return answer;
}
'프로그래머스' 카테고리의 다른 글
도둑질 C++ (0) | 2021.10.06 |
---|---|
셔틀버스 C++ (0) | 2021.10.03 |
불량 사용자 C++ (0) | 2021.10.02 |
자물쇠와 열쇠 C++ (0) | 2021.08.22 |
매출 하락 최소화 C++ (0) | 2021.08.09 |