diff --git a/problems/week12/CodingRoom_01/YeoroJeong/one.cpp b/problems/week12/CodingRoom_01/YeoroJeong/one.cpp new file mode 100644 index 0000000..df5a01e --- /dev/null +++ b/problems/week12/CodingRoom_01/YeoroJeong/one.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +map cost; +mapmargin; +int solution(vector ings, vector menu, vector sell) { + // 여기에 풀이를 작성하세요. + int result = 0; + // 재료별 단가를 저장해 메뉴 원가를 계산할 때 조회한다. + for (auto c : ings) { + stringstream ss(c); + char idx; + string cost_str; + ss >> idx >> cost_str; + cost[idx] = stoi(cost_str); + } + + // 필요한 재료의 단가를 더한 뒤 판매가에서 빼 메뉴당 이익을 계산한다. + for (auto m : menu) { + stringstream ss(m); + string idx; + string needs; + string cost_str; + ss >> idx >> needs >> cost_str; + int temp_cost = 0; + for (int i = 0; i < needs.length(); i++) { + temp_cost += cost[needs[i]]; + } + margin[idx] = stoi(cost_str) - temp_cost; + } + // 메뉴당 이익에 판매 수량을 곱해 하루 총이익에 더한다. + for (auto s : sell) { + stringstream ss(s); + string idx; + string cost_str; + ss >> idx >> cost_str; + result = result + (margin[idx] * (stoi(cost_str))); + } + return result; +} diff --git a/problems/week12/CodingRoom_02/YeoroJeong/two.cpp b/problems/week12/CodingRoom_02/YeoroJeong/two.cpp new file mode 100644 index 0000000..6476786 --- /dev/null +++ b/problems/week12/CodingRoom_02/YeoroJeong/two.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +struct Fruit { + int idx; + vectorlist; +}; +struct Comp { + bool operator()(const Fruit& a, const Fruit& b)const { + // 우선순위 순으로 나열한 점수를 비교해 처음으로 점수가 큰 과일을 앞에 둔다. + for (int i = 0; i < a.list.size(); i++) { + if (a.list[i] != b.list[i]) return a.list[i] > b.list[i]; + } + // 점수가 모두 같으면 원래 번호가 작은 과일을 앞에 둔다. + return a.idx < b.idx; + } +}; +vector solution(vector> fruits, vector> priority) { + // 여기에 풀이를 작성하세요. + vectorresult; + int siz = fruits[0].size(); + set solv; + for (int i = 0; i < fruits.size(); i++) { + deque dq; + int cur_imp = 1; + int cur_idx = 0; + // 우선순위 1부터 차례대로 해당 열을 찾아 비교할 점수 목록을 만든다. + while (cur_imp <= siz) { + if (priority[i][cur_idx] == cur_imp) { + dq.push_back(fruits[i][cur_idx]); + cur_imp++; + cur_idx = 0; + continue; + } + cur_idx++; + } + vectortemp; + while (!dq.empty()) { + temp.push_back(dq.front()); + dq.pop_front(); + } + + solv.insert({ i + 1,temp }); + + } + // set에 정렬된 순서대로 과일의 원래 번호를 반환 배열에 담는다. + for (auto temp : solv) { + result.push_back(temp.idx); + } + + return result; +} diff --git a/problems/week12/CodingRoom_03/YeoroJeong/tree.cpp b/problems/week12/CodingRoom_03/YeoroJeong/tree.cpp new file mode 100644 index 0000000..bffa839 --- /dev/null +++ b/problems/week12/CodingRoom_03/YeoroJeong/tree.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +vectorresult; +vectorcost; +bool first = true; +bool Comp(const vector& a, const vector& b) { + for (int i = 0; i < a.size(); i++) { + if (a[i] != b[i]) return a[i] < b[i]; + } + return true; +} +int n; +// valid_idx는 남은 원소의 초기 배열 인덱스 목록이고, sep는 그중 stack1에 있는 원소의 개수다. +void solv(int target,int sep,vectorvalid_idx,vectortemp ) { + // 초기 배열을 모두 채우면 현재까지 찾은 배열 중 사전순 최솟값을 갱신한다. + if (target>n) { + if (first) { + result = temp; + first = false; + return; + } + if (Comp(temp, result)) { + result = temp; + } + return; + } + // 두 스택을 stack1의 바닥부터 stack2의 바닥까지 한 줄로 보면 원소 이동은 경계만 바꾼다. + int move_cnt = cost[target - 1]; + // 경계에서 이동 비용만큼 떨어진 왼쪽과 오른쪽 칸이 추출 후보가 된다. + int left = sep - 1 - move_cnt; + int right = sep + move_cnt; + if (left >= 0) { + vectornext_temp; + int next_idx = valid_idx[left]; + vectornext_valid; + next_valid = valid_idx; + next_valid.erase(find(next_valid.begin(), next_valid.end(), next_idx)); + + next_temp = temp; + next_temp[next_idx] = target; + + // 추출한 칸 왼쪽에 남은 원소의 개수가 새 경계가 된다. + solv(target + 1, left,next_valid, next_temp); + } + if (right < valid_idx.size()) { + vectornext_temp; + int next_idx = valid_idx[right]; + vectornext_valid; + next_valid = valid_idx; + next_valid.erase(find(next_valid.begin(), next_valid.end(), next_idx)); + + next_temp = temp; + next_temp[next_idx] = target; + + solv(target + 1, right,next_valid, next_temp); + } + + +} +vector solution(vector costs) { + // 여기에 풀이를 작성하세요. + first = true; + cost = costs; + n = costs.size(); + result.resize(n); + // 처음에는 stack2가 비어 있으므로 꼭대기에서 costs[0]칸 아래에 1이 있다. + int first_idx = n - costs[0]; + result[first_idx-1] = 1; + vectorvalid; + for (int i = 0; i < n; i++) { + valid.push_back(i); + } + valid.erase(find(valid.begin(), valid.end(), first_idx - 1)); + + solv(2,first_idx-1,valid,result); + + return result; +}