백준
[백준] 5397번 키로거 (리스트, c++)
해랑쓰
2021. 9. 27. 10:01
728x90
반응형
https://www.acmicpc.net/problem/5397
커서 (현재 보고 있는 위치)에 동적으로 추가 삭제, 그리고 링크 이동을 연습하는 문제
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
using namespace std;
int t;
string s;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
list<char> li;
cin >> s;
auto cursor = li.end();
for (auto c : s) {
if (c == '<') {
if (cursor != li.begin()) {
cursor--;
}
}
else if (c == '>') {
if (cursor != li.end()) {
cursor++;
}
}
else if (c == '-') {
if (cursor != li.begin()) {
cursor--;
cursor = li.erase(cursor);
}
}
else {
li.insert(cursor, c);
}
}
for (auto x : li) {
cout << x;
}
cout << "\n";
}
return 0;
}
728x90
반응형