Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions problems/week12/CodingRoom_01/YeoroJeong/one.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
using namespace std;
map<char, int> cost;
map<string, int>margin;
int solution(vector<string> ings, vector<string> menu, vector<string> 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;
}
58 changes: 58 additions & 0 deletions problems/week12/CodingRoom_02/YeoroJeong/two.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <deque>
#include<set>
using namespace std;
struct Fruit {
int idx;
vector<int>list;
};
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<int> solution(vector<vector<int>> fruits, vector<vector<int>> priority) {
// 여기에 풀이를 작성하세요.
vector<int>result;
int siz = fruits[0].size();
set<Fruit,Comp> solv;
for (int i = 0; i < fruits.size(); i++) {
deque<int> 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++;
}
vector<int>temp;
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;
}
83 changes: 83 additions & 0 deletions problems/week12/CodingRoom_03/YeoroJeong/tree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
using namespace std;
vector<int>result;
vector<int>cost;
bool first = true;
bool Comp(const vector<int>& a, const vector<int>& 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,vector<int>valid_idx,vector<int>temp ) {
// 초기 배열을 모두 채우면 현재까지 찾은 배열 중 사전순 최솟값을 갱신한다.
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) {
vector<int>next_temp;
int next_idx = valid_idx[left];
vector<int>next_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()) {
vector<int>next_temp;
int next_idx = valid_idx[right];
vector<int>next_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<int> solution(vector<int> 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;
vector<int>valid;
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;
}
Loading