[BOJ] 5397 키로거

Time Lapse :NONE

5397.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream> 
#include <list>
#include <string>
#pragma warning(disable:4996)
using namespace std;

int main() {
int T; cin >> T;
for(int i=0;i<T;i++){
string L; cin >> L;
list<char> keylog;
list<char>::iterator it = keylog.begin();
int len = L.size();
for(int j=0;j<len;j++){
switch (L[j]) {
case '<':
if (it != keylog.begin())
it--;
break;
case '>':
if (it != keylog.end())
it++;
break;
case '-':
if (it != keylog.begin())
keylog.erase((--it)++);
break;
default:
keylog.insert(it, L[j]);
break;
}
}
for (auto c : keylog)
printf("%c", c);
printf("\n");
}
return 0;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/5397/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.