统计一个字符串中出现了多少个不同的字符

#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
/*
输入:  abcdefaa

输出
1 1 1 1 1 1 2 3 
6
1
*/
int main()
{
    string s;
    cin>>s;
    map<char,int>c;
    //求一个字符串中有多少个不同的字符
    for(int i=0;i<s.size();i++)
    {
        c[s[i]]++;
        cout<<c[s[i]]<<" ";
    }
    cout<<endl<<c.size()<<endl;
    cout<<c.count('c');
    return 0;
}
原文地址:https://www.cnblogs.com/forward-985/p/13848664.html