代码
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
char str[200];
scanf("%s",str);
multimap<char,int> set;
vector<char> occur;//----记录第一次出现的字符
vector<char>::iterator it;
for (int i = 0; str[i] != '\0' ; ++i) {
set.insert({str[i],i});
if (set.count(str[i]) == 1){
occur.push_back(str[i]);
}
}
for ( it = occur.begin(); it != occur.end() ; ++it) {
if(set.count(*it) > 1){//----字符重复出现
multimap<char,int>::iterator it2 = set.lower_bound(*it);//---lower_bound(key)返回key对应的第一个值的位置
printf("%c:%d",it2->first,it2->second);
for ( it2 = ++set.lower_bound(*it); it2 != set.upper_bound(*it) ; ++it2){//----upper_bound(key)返回key对应的最后一个值的后一个位置
printf(",%c:%d",it2->first,it2->second);
}
printf("\n");
}
}
return 0;
}