题解 | #找位置#
找位置
https://www.nowcoder.com/practice/e3b2cc44aa9b4851bdca89dd79c53150
#include <bits/stdc++.h> #include <utility> using namespace std; class myChar { public: char c; vector<int>index; }; int main() { string s; while (getline(cin, s)) { vector<myChar>m; for (int i = 0; i < s.length(); i++) { bool isFind = false; for(int j =0;j<m.size();j++) if(m[j].c == s[i]){ m[j].index.push_back(i); isFind=true; } if (false == isFind) { myChar temp; temp.c = s[i]; temp.index.push_back(i); m.push_back(temp); } } for (auto mychar : m) { if (mychar.index.size() > 1) { for (int i = 0; i < mychar.index.size(); i++) { if (i<mychar.index.size()-1)cout<<mychar.c<<":"<<mychar.index[i]<<","; else cout << mychar.c << ":" << mychar.index[i] << endl; } } } } } // 64 位输出请用 printf("%lld")