[伯俊]5397キーホルダー
白駿5397鍵錠 https://www.acmicpc.net/problem/5397
#include <iostream>
#include <string>
#include <deque>
using namespace std;
deque <char> leftDQ;
deque <char> rightDQ;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
cin >> T;
while (T--) {
string input;
cin >> input;
for (int i = 0; input[i] != NULL; ++i) {
char x = input[i];
//커서 왼쪽으로
if (x == '<') {
if (leftDQ.empty()) continue;
char tmp = leftDQ.back();
leftDQ.pop_back();
rightDQ.push_front(tmp);
}
//커서 오른쪽으로
else if (x == '>') {
if (rightDQ.empty()) continue;
char tmp = rightDQ.front();
rightDQ.pop_front();
leftDQ.push_back(tmp);
}
//커서 왼쪽 문자 삭제
else if (x == '-') {
if (leftDQ.empty()) continue;
leftDQ.pop_back();
}
//커서 왼쪽 문자 추가
else {
leftDQ.push_back(x);
}
}
for (auto it = leftDQ.begin(); it != leftDQ.end(); ++it)
cout << *it;
for (auto it = rightDQ.begin(); it != rightDQ.end(); ++it)
cout << *it;
cout << endl;
leftDQ.clear();
rightDQ.clear();
}
return 0;
}
Reference
この問題について([伯俊]5397キーホルダー), 我々は、より多くの情報をここで見つけました https://velog.io/@sunjoo9912/백준-5397-키로거テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol