Computer Scientists are Pretty Pessimistic

Tuesday, 1 March 2016

Use of Map in C++

#include <iostream>
#include <map>
#include <string>
#include <cstdio>
using namespace std;
int main ()
{
    string str;
    getline(cin,str);
    map<char,int>mp;
    for(int i=0;i<str.length();i++)
        mp[str[i]]++;
    for(int i='a';i<='z';i++)
        if(mp[i]>1)
            printf("%c %d\n",i,mp[i]);
    return 0;
}

No comments:

Post a Comment