-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathDifferent-names.cpp
57 lines (41 loc) · 1 KB
/
Different-names.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Name: Mehul Chaturvedi
IIT-Guwahati
*/
/*
In Little Flowers Public School, there are many students with same first names.
You are given a task to find the students with same names.
You will be given a string comprising of all the names of students and you have
to tell the name and count of those students having same. If all the names are unique, print -1 instead.
Note: We don't have to mention names whose frequency is 1.
*/
#include <bits/stdc++.h>
using namespace std;
int main( int argc , char ** argv )
{
ios_base::sync_with_stdio(false) ;
cin.tie(NULL) ;
string names;
getline(cin, names);
//cout << names << '\n';
stringstream iss(names);
unordered_map<string, int> m1;
string temp;
while(iss>>temp){
m1[temp]++;
}
unordered_map<string, int> :: iterator it=m1.begin();
int count = 0;
for (it; it != m1.end(); ++it)
{
if(it->second>1){
cout << it->first<<" "<< it->second << '\n';
count++;
}
}
if (count == 0)
{
cout << -1 << '\n';
}
return 0 ;
}