From 5aedf378446307962d28cb7bdb2bdce3631ca631 Mon Sep 17 00:00:00 2001 From: Seojin Date: Wed, 12 Jun 2024 15:16:59 +0900 Subject: [PATCH] Week1 --- ksj/week1/1158.cpp | 32 +++++++++++++++++++++++++ ksj/week1/1406.cpp | 51 +++++++++++++++++++++++++++++++++++++++ ksj/week1/5397.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 ksj/week1/1158.cpp create mode 100644 ksj/week1/1406.cpp create mode 100644 ksj/week1/5397.cpp diff --git a/ksj/week1/1158.cpp b/ksj/week1/1158.cpp new file mode 100644 index 0000000..79615f9 --- /dev/null +++ b/ksj/week1/1158.cpp @@ -0,0 +1,32 @@ +#include +#include +using namespace std; +int main() +{ + int N, K; + queue yose; + cin >> N >> K; + + for (int i = 1; i <= N; i++) + yose.push(i); + + while (!yose.empty()) + { + for (int i = 0; i < K - 1; i++) + { + yose.push(yose.front()); + yose.pop(); + } + + if (yose.size() == N) + cout << "<"; + + cout << yose.front(); + yose.pop(); + + if (yose.size() == 0) + cout << ">"; + else + cout << ", "; + } +} diff --git a/ksj/week1/1406.cpp b/ksj/week1/1406.cpp new file mode 100644 index 0000000..fafbb3a --- /dev/null +++ b/ksj/week1/1406.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +using namespace std; +int main() +{ + string str, cmd; + int M, str_len; + deque c_left, c_right; // 커서 왼쪽의 문자열, 커서 오른쪽의 문자열 + + cin >> str >> M; + + str_len = str.length(); + + for (int i = 0; i < str_len; i++) // 초기값 설정(처음엔 모든 문자열의 커서 왼쪽에 위치) + c_left.push_back(str[i]); + + cin.ignore(); + + for (int i = 0; i < M; i++) // 명령어 입력 + { + getline(cin, cmd); + + if (cmd[0] == 'L' && !c_left.empty()) // L 명령어 + { + c_right.push_front(c_left.back()); + c_left.pop_back(); + } + else if (cmd[0] == 'D' && !c_right.empty()) // D 명령어 + { + c_left.push_back(c_right.front()); + c_right.pop_front(); + } + else if (cmd[0] == 'B' && !c_left.empty()) // B 명령어 + c_left.pop_back(); + else if (cmd[0] == 'P') // P 명령어 + c_left.push_back(cmd[2]); + } + + while (!c_left.empty()) // 순서대로 문자열 출력 + { + cout << c_left.front(); + c_left.pop_front(); + } + + while (!c_right.empty()) // 순서대로 문자열 출력 + { + cout << c_right.front(); + c_right.pop_front(); + } +} diff --git a/ksj/week1/5397.cpp b/ksj/week1/5397.cpp new file mode 100644 index 0000000..ec9b26b --- /dev/null +++ b/ksj/week1/5397.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +using namespace std; +int main() +{ + int T; + string pwd; + + cin >> T; + + for (int i = 0; i < T; i++) + { + deque c_left; + deque c_right; + cin >> pwd; + + for (int j = 0; j < pwd.length(); j++) + { + if (pwd[j] == '<') + { + if (!c_left.empty()) + { + c_right.push_front(c_left.back()); + c_left.pop_back(); + } + } + else if (pwd[j] == '>') + { + if (!c_right.empty()) + { + c_left.push_back(c_right.front()); + c_right.pop_front(); + } + } + else if (pwd[j] == '-') + { + if (!c_left.empty()) + c_left.pop_back(); + } + else + { + c_left.push_back(pwd[j]); + } + } + + while (!c_left.empty()) + { + cout << c_left.front(); + c_left.pop_front(); + } + + while (!c_right.empty()) + { + cout << c_right.front(); + c_right.pop_front(); + } + cout << '\n'; + } +}