-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path144_Teclado_roto.cpp
70 lines (59 loc) · 1.12 KB
/
144_Teclado_roto.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Usuario de Acepta el reto: jjjjjjjp022
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <list>
// función que resuelve el problema
std::list<char> resolver(std::string ramiro) {
// - Inicio
// + Fin
// * Derecha
// 3 Supr
//Usar iteradores
std::list<char> teclado;
auto it = teclado.begin();
for (const char& l : ramiro)
{
switch (l)
{
case '-': it = teclado.begin();
break;
case '+':
it = teclado.end();
break;
case '*': {
if (teclado.end() != it)
++it;
}
break;
case '3': {
if (teclado.end() != it)
it = teclado.erase(it);
}
break;
default: teclado.insert(it, l);
}
}
return teclado;
}
// Resuelve un caso de prueba, leyendo de la entrada la
// configuración, y escribiendo la respuesta
bool resuelveCaso() {
// leer los datos de la entrad
std::string ramiro;
std::getline(std::cin, ramiro);
if (!std::cin)
return false;
std::list<char> teclado = resolver(ramiro);
// escribir sol
for (const char& l : teclado)
std::cout << l;
std::cout << '\n';
return true;
}
int main() {
while (resuelveCaso())
;
return 0;
}