diff --git "a/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/10866.cpp" "b/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/10866.cpp" new file mode 100644 index 0000000..31fe4ee --- /dev/null +++ "b/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/10866.cpp" @@ -0,0 +1,113 @@ +#include +#include + +using namespace std; +const int SIZE = 10001; + +int front_pointer = 0, rear_pointer = 0; +vector deque_vec(SIZE); + +bool empty(){ + return front_pointer == rear_pointer; +} + +void push_front(int k){ + front_pointer = (front_pointer+1) % SIZE; + deque_vec[front_pointer] = k; +} + +void push_back(int k){ + rear_pointer = (rear_pointer+1) % SIZE; + deque_vec[rear_pointer] = k; +} + +int pop_front(){ + front_pointer = (front_pointer + 1) % SIZE; + return deque_vec[front_pointer]; +} + +int pop_back(){ + rear_pointer = (rear_pointer + 1) % SIZE; + return deque_vec[rear_pointer]; +} + +int size(){ + int tmp = (rear_pointer - front_pointer); + if(tmp < 0){ + tmp += SIZE; + } + return tmp; +} + +int front() { + int tmp = (front_pointer + 1) % SIZE; + return deque_vec[tmp]; +} + +int back() { + return deque_vec[rear_pointer]; +} + +int main(){ + int n, k; + string cmd; + deque dq; + + cin >> n ; + while(n--){ + cin >> cmd; + if(cmd == "push_front"){ + cin >> k; + dq.push_front(k); + continue; + } + if(cmd == "push_back"){ + cin >> k; + dq.push_back(k); + continue; + } + if(cmd == "pop_back"){ + if(dq.empty()) + cout << -1 << '\n'; + else{ + cout << dq.back() << '\n'; + dq.pop_back(); + } + continue; + } + if(cmd == "pop_front"){ + if(dq.empty()) + cout << -1 << '\n'; + else{ + cout << dq.front() << '\n'; + dq.pop_front(); + } + continue; + } + if(cmd == "size"){ + cout << dq.size() << '\n'; + continue; + } + if(cmd == "empty"){ + cout << dq.empty() << '\n'; + continue; + } + if(cmd == "front"){ + if(dq.empty()) + cout << -1 << '\n'; + else{ + cout << dq.front() << '\n'; + } + continue; + } + if(cmd == "back"){ + if(dq.empty()) + cout << -1 << '\n'; + else{ + cout << dq.back() << '\n'; + } + continue; + } + } + +} \ No newline at end of file diff --git "a/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/1935.cpp" "b/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/1935.cpp" new file mode 100644 index 0000000..8cfbee7 --- /dev/null +++ "b/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/1935.cpp" @@ -0,0 +1,66 @@ + +#include +#include +#include +#include + +using namespace std; + +int main() { + int n; + cin >> n; + + string s; + cin >> s; + + //피연산자의 값 입력 + double t; + map value; + for (int i = 0; i < n; i++) { + cin >> t; + value['A' + i] = t; + } + + stack st; + + for(int i=0; i= 'A' && c <='Z'){ + st.push(value[c]); + } + else if(c == '*'){ + a = st.top(); + st.pop(); + b = st.top(); + st.pop(); + st.push(a*b); + } + else if(c == '+'){ + a = st.top(); + st.pop(); + b = st.top(); + st.pop(); + st.push(a+b); + } + else if(c == '/'){ + a = st.top(); + st.pop(); + b = st.top(); + st.pop(); + st.push(b/a); + } + else if(c == '-'){ + a = st.top(); + st.pop(); + b = st.top(); + st.pop(); + st.push(b-a); + } + } + + cout << fixed; + cout.precision(2); + cout << st.top(); + +} \ No newline at end of file diff --git "a/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/20920.cpp" "b/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/20920.cpp" new file mode 100644 index 0000000..914c82b --- /dev/null +++ "b/9\354\233\224 15\354\235\274 - \354\212\244\355\203\235, \355\201\220, \353\215\261/20920.cpp" @@ -0,0 +1,40 @@ + +#include +#include +#include +#include + +using namespace std; + +bool cmp(const pair &i1, const pair &i2){ + if(i1.second != i2.second) + return i1.second > i2.second; + if(i1.first.size() != i2.first.size()) + return i1.first.size() > i2.first.size(); + return i1.first < i2.first; +} +int main(){ + + int n, len; + cin >> n >> len; + + //맵에 단어와 횟수를 입력 + map word; + for(int i=0; i> s; + if(s.length() >= len) + word[s]++; + } + + //벡터에 맵 입력 + vector> answer(word.begin(), word.end()); + //정렬 + sort(answer.begin(), answer.end(), cmp); + + //출력 + for(int i=0; i +#include +#include + +using namespace std; + +int solution(vector> board, vector moves) { + int answer = 0; + int n = board.size(); + vector> doll(n); + + //스택에 인형 종류 입력 + for(int i=n-1; i>=0; i--){ + for(int j=0; j moved; + int prev = 0; + //인형 옮기기 + for(int move : moves){ + if(doll[move-1].empty()) + continue; + int k = doll[move-1].top(); + doll[move-1].pop(); + if(k==prev){ //연속해서 쌓였다면 + moved.pop(); + //바구니가 비지 않았다면 마지막 값 입력, 비었다면 0 입력 + if(!moved.empty()){ + prev = moved.top(); + } + else{ + prev = 0; + } + answer += 2; + } + else{ + moved.push(k); + prev = k; + } + } + + return answer; +} + +int main() { + vector> board = {{0, 0, 0, 0, 0}, + {0, 0, 1, 0, 3}, + {0, 2, 5, 0, 1}, + {4, 2, 4, 4, 2}, + {3, 5, 1, 3, 1}}; + vector moves = {1, 5, 3, 5, 1, 2, 1, 4}; + cout << solution(board, moves); +} \ No newline at end of file