-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5397.cpp
More file actions
59 lines (54 loc) · 817 Bytes
/
5397.cpp
File metadata and controls
59 lines (54 loc) · 817 Bytes
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// 5397. 키로거
// 2019.05.21
// 스택, 배열, 시뮬레이션, 링크드 리스트
#include<iostream>
#include<string>
#include<list>
using namespace std;
int main()
{
int t;
cin >> t;
for (int testCase = 1; testCase <= t; testCase++)
{
string s;
cin >> s;
list<char> list;
auto cur = list.begin();
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '<')
{
if (cur != list.begin())
{
cur--;
}
}
else if (s[i] == '>')
{
if (cur != list.end())
{
cur++;
}
}
else if (s[i] == '-')
{
if (cur != list.begin())
{
cur--;
cur = list.erase(cur);
}
}
else
{
list.insert(cur, s[i]);
}
}
for (auto iter = list.begin(); iter != list.end(); iter++)
{
cout << *iter;
}
cout << endl;
}
return 0;
}