暴力了,没想到更好一点的解决办法
#include <iostream>
#include <string>
using namespace std;
struct str{
char a;
int pos;
};
int main() {
string s;
cin>>s;
str *st = new str[s.length()];
int flag=1;
for(int i=0;i<s.length();i++)
{
st[i].a=s[i];
st[i].pos=1;
}
for(int i=0;i<s.length();i++)
{
if(st[i].pos==0);
else
{
for(int j=i+1;j<s.length();j++)
{
if(st[i].a==st[j].a)
{
if(flag)
{
cout<<st[i].a<<":"<<i;
flag=0;
}
cout<<","<<st[i].a<<":"<<j;
st[j].pos=0;
}
}
if(!flag)
cout<<endl;
}
flag=1;
}
}