程式碼
#include <iostream> #include <string> using namespace std; int main() { string s; while (cin >> s) { string ans = ""; int index = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '[') { index = 0; } else if (s[i] == ']') { index = ans.size() ; if (index < 0) index = 0; } else { ans.insert(index, string(1, s[i])); index++; } } cout << ans << endl; } return 0; }
沒有留言:
張貼留言