Duplicate character

Duplicate Character

Tina is given a string SS which contains the first letter of all the student names in her class. She got a curiosity to check how many people have their names starting from the same alphabet. So given a string SS, she decided to write a code that finds out the count of characters that occur more than once in the string.

Input format

The first line contains an integer TT, denoting the number of test cases. Each test case consists of a string SS containing only lowercase characters.

Output format

For each test case on a new line, print the output in the format character=count . If multiple characters have more than one count, print all of them separated by space, in alphabetical order. In case no such character is present print −1−1.

Constraints

1<=T<=71<=T<=7 1<=|S|<=1071<=|S|<=107, where |S||S| denotes length of string SS.

Time limit

11 ​secon

Example

Input

33 prepbytes java algorithm

Output

e=2 p=2
a=2
−1

Sample test case explanation

In the first string character p is occuring 2 times and character e is occuring 2 times. Printing them in alphabetical order we get,

e=2 p=2

question link=https://mycode.prepbytes.com/problems/strings/DUPTCHAR

#include <bits/stdc++.h>
using namespace std;
void solveq()
{
string s;
cin>>s;
long int n=s.length();
map<char,int>mp;
map<char,int>::iterator it;
for(int i=0;i<n;i++)
{
mp[s[i]]++;

}
sort(s.begin(),s.end());
int f=0;

for(it=mp.begin();it!=mp.end();it++)
{

 if(it->second>1)
 {
 f=1;
  cout<<it->first<<"="<<it->second<<" ";
 }

}
if(f==0)
cout<<-1;

}

int main()
{
int t;
cin>>t;
while(t–)
{
solveq();
cout<<endl;
}
}

No need to sort the string , can improve the complexity with simple frequency Table.