统计字符串中重复的字符个数并输出

//输出字符串各个字符的个数
/*
对重复的字符将其下标存放在vector中,使用unique函数只保存一份重复字符的数字
通过下标查找到相应的字符,从map中取出对应的统计数字
*/

include “iostream”

include “windows.h”

include “string”

include “map”

include “vector”

include “algorithm”

include “iterator”

using namespace std;

int main()
{

vector coll,coll1;
string str;
int len;
int nn;
char word;
cin>>str;

int index;
map counts;
len=str.length();
int i;

vector::iterator pos;
for(i=0; i::iterator num(counts.find(cha));//开始统计计数
    if(num->second>1)
    {
        coll.push_back(index);
    }
}
sort(coll.begin(),coll.end());
pos=unique(coll.begin(),coll.end());
//copy(coll.begin(),pos,ostream_iterator(cout, " "));
copy(coll.begin(),pos,back_inserter(coll1));
//copy(coll1.begin(),coll1.end(),ostream_iterator(cout," "));
for(i=0; i::iterator num1(counts.find(ch));
    cout<first<<" ";
    cout<second<

}

你可能感兴趣的:(C/C++)