求助:在不改变思路的情况下,简化这段代码

UVA11988 Broken Keyboard (a.k.a. Beiju Text)

~~压行~~
by 今天也要开心a @ 2020-08-05 09:51:17


```cpp #include <bits/stdc++.h> using namespace std; string s; list<char> ls; int main() { while (getline(cin, s)) { list<char>::iterator it = ls.begin(); for (const char &c : s) { if (c == '[') it = ls.begin(); //光标回到首位 else if (c == ']') it = ls.end(); //光标回到末位 else { it = ls.insert(it, c); ++it; } //在光标位置插入字符,光标指向原本的位置 } for (auto it = ls.begin(); it != ls.end(); ++it) printf("%c", *it); printf("\n"); s.clear(); ls.clear(); } return 0; } ```
by Lethargy @ 2021-05-19 18:42:41


@[Lethargy](/user/244313) **6**
by FateReset_ @ 2023-02-18 10:32:59


# ~~6~~
by Jayant_xincheng @ 2023-05-13 20:29:11


|