Created
July 28, 2019 19:07
-
-
Save aliciawyy/78378b60c6c6f4b58a6f052766f17972 to your computer and use it in GitHub Desktop.
UVa 11988 Broken Keyboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
/* Solve the problem with double-linked list | |
* We just need to record and update the next position to insert | |
* the character. | |
*/ | |
int main() { | |
string line; | |
while (getline(cin, line)) { | |
list<char> ans; | |
auto next_pos = ans.end(); | |
for (auto ch : line) { | |
if (ch == '[') { | |
next_pos = ans.begin(); | |
} else if (ch == ']') { | |
next_pos = ans.end(); | |
} else { | |
next_pos = next(ans.insert(next_pos, ch)); | |
} | |
} | |
cout << string(ans.begin(), ans.end()) << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment