-
Notifications
You must be signed in to change notification settings - Fork 12
/
AceptaElReto679FacundoUndo.cpp
56 lines (54 loc) · 1.11 KB
/
AceptaElReto679FacundoUndo.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <string>
#include <list>
using namespace std;
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int num_casos;
cin >> num_casos;
for (int i = 0; i < num_casos; ++i) {
string palabra;
list<string> escrito;
list<string> guardado;
cin >> palabra;
while (palabra != ".") {
if (palabra == "<") {
if (!escrito.empty()) {
guardado.push_front(escrito.back());
escrito.pop_back();
}
}
else if (palabra == ">") {
if (guardado.empty()) {
if (!escrito.empty()) {
escrito.push_back(escrito.back());
}
}
else {
escrito.push_back(guardado.front());
guardado.pop_front();
}
}
else {
escrito.push_back(palabra);
guardado.clear();
}
cin >> palabra;
}
if (escrito.empty()) {
cout << '\n';
continue;
}
else if (escrito.size() == 1) {
cout << escrito.front() << '\n';
continue;
}
auto ultimo = escrito.end();
ultimo--;
for (auto it = escrito.begin(); it != ultimo; it++) {
cout << *it << ' ';
}
cout << *ultimo << '\n';
}
}