时间复杂度为 O(n) #include <algorithm> #include <vector> using namespace std; int main() { string s; while (cin >> s) { vector <vector <int >> v(128); for (int i = 0; i < s.size(); i++) { v[s[i]].push_back(i); } ...