Answers for "cpp how to repeat characters"

C++
3

repeat character n times c++

auto five_repeated_dots = std::string(5, '.');
Posted by: Guest on September-14-2020
0

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
*/
Posted by: Guest on January-08-2022

Browse Popular Code Answers by Language