Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

print duplicate characters from string in c++

#include<iostream>
#include<unordered_map>
#include<string>
using namespace std;
void printdub(string st)
{
    unordered_map <char, int> mp;
    for(int i=0; i<st.length(); i++)
    {
        mp[st[i]]++;
    }
    for(auto it : mp)
    {
        if(it.second>1)
        {
            cout<<it.first<<", total_count="<<it.second<<endl;
        }
    }
}

int main()
{
    string st;
    cin>>st;
    printdub(st);
    return 0;
}

/*
geeksofgeeks
s, total_count=2
k, total_count=2
e, total_count=4
g, total_count=2
*/
 
PREVIOUS NEXT
Tagged: #print #duplicate #characters #string
ADD COMMENT
Topic
Name
2+8 =