#include <iostream> using namespace std; #include<vector> #include<algorithm> typedef pair<char, int>pci; int main() { string s; cin >> s; vector<pci>q; int count[110] = { 0 }; for (int i = 0; i < s.size(); i++) { q.push_back({ s[i],i }); count[s[i] - '0']++;//记录重复的数值 } bool flag[110] = { false };//记录是否输出过 for (int k = 0; k < s.size(); k++) { if (count[s[k] - '0'] > 1) { //该数值重复 for (int j = k; j < s.size(); j++) { if ((q[k].first == q[j].first) && flag[j] == false) {//是重复的且还未输出则输出 { count[s[k] - '0']--; cout << q[j].first << ':' << q[j].second; if (count[s[k] - '0'] >=1) cout << ','; } flag[j] = true; } } cout << endl; } } }