class Solution { public: string reverseOnlyLetters(string S) { int len = S.length(); queue<char> Q; stack<char> ST; vector<int> V; for (int i = 0; i < len; i++) { char c = S[i]; //小写 ASCII[97,122] //大写 ASCII[65,90] if ((c >= 97 && c <= 122) || (c >= 65 && c <= 90))//字母 { ST.push(c); } else//符号 { Q.push(c); V.push_back(i); } } string R; for (int i = 0; i < len; i++) { char c = 0; if (find(V.begin(), V.end(), i) == V.end())//当前应该是一个字符 { c = ST.top(); ST.pop(); } else { c = Q.front(); Q.pop(); } R += c; } return R; } };