Skip to content

Commit 671815a

Browse files
Count Me Remains Unsolved
1 parent e6c90c2 commit 671815a

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"name":"Count Me","group":"HackerRank - Final Exam | Basic Data Structure | Batch 05","url":"https://www.hackerrank.com/contests/final-exam-a-basic-data-structure-a-batch-05/challenges/count-me-2","interactive":false,"memoryLimit":512,"timeLimit":4000,"tests":[{"input":"1\nRatul loves to play football when he gets time but Ratul is not a good player so his teacher asked Ratul if he can play with him so that Ratul can progress\n","output":"Ratul 4\n","id":1725184488591},{"input":"2\nratul piyush fohad shuvo rafi piyush fohad ratul\njony jony yes papa eating sugar no papa telling lies no papa open your mouth ha ha ha\n","output":"piyush 2\npapa 3\n","id":1725184488570}],"testType":"single","input":{"type":"stdin"},"output":{"type":"stdout"},"languages":{"java":{"mainClass":"Main","taskClass":"CountMe"}},"batch":{"id":"4357920d-6793-4613-b7b9-fcc3039a613d","size":1},"srcPath":"c:\\xampp\\htdocs\\Phitron\\Basic_Data_Structures\\Final Exam Problems\\Count_Me.cpp"}

Final Exam Problems/Count_Me.bin

112 KB
Binary file not shown.

Final Exam Problems/Count_Me.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int t;
7+
cin >> t;
8+
while (t--)
9+
{
10+
cin.ignore();
11+
string sentence;
12+
getline(cin, sentence);
13+
string word;
14+
stringstream ss(sentence);
15+
map<string, int> mp;
16+
17+
while (ss >> word)
18+
{
19+
mp[word]++;
20+
}
21+
22+
string maxWord;
23+
int maxCount = 0;
24+
for (auto it = mp.begin(); it != mp.end(); it++)
25+
{
26+
if (it->second > maxCount)
27+
{
28+
maxWord = it->first;
29+
maxCount = it->second;
30+
}
31+
}
32+
33+
cout << maxWord << " " << maxCount << endl;
34+
}
35+
36+
return 0;
37+
}

0 commit comments

Comments
 (0)