C++ Competition Daily Problem – Day 704

Today is the 704th day of learning programming with the cool rain!

Hello, everyone! This is the problem from the GESP Level 3 Examination.

Day 704

C++ Competition Daily Problem - Day 704C++ Competition Daily Problem - Day 704

GESP Level 3 Examination in March 2025

Problem 2: Word Frequency Count

Problem Description

In text processing, counting the frequency of words is a common task. Now, given n words, you need to find the word that appears the most frequently. In this problem, ignore the case of the letters in the words (i.e., Apple, apple, APPLE, aPPle, etc. are considered the same word).

Please write a program that takes n words as input and outputs the word that appears the most frequently.

Input Format

The first line contains an integer n, indicating the number of words;

the next n lines each contain one word, composed of uppercase and lowercase English letters.

It is guaranteed that there will be only one word that appears the most frequently.

Output Format

Output one line containing the word that appears the most frequently (the output word should be in lowercase).

【Input】

6

Apple

banana

apple

Orange

banana

apple

【Output】

apple

Answer:

START OF SPRING

Solution

#include<bits/stdc++.h>using namespace std;// Cool Rain 666string a[101];map<string, int> mp;int main(){  int n,cnt=0,m=-1;  cin>>n;  for(int i=1;i<=n;i++){    cin>>a[i];  }  for(int i=1;i<=n;i++){    string str=a[i];    transform(str.begin(), str.end(), str.begin(), ::tolower);    if(mp.count(str)==0){      mp[str]=0;    }    m = max(m, ++mp[str]);  }  for(auto it = mp.begin(); it != mp.end(); it++)    if ((it->second) == m) {      cout << (it->first) << '\n';    }  return 0;}

C++ Competition Daily Problem - Day 704

20

25

4

C++ Competition Daily Problem - Day 704

APRIL

Day

Monday

Tuesday

Wednesday

Thursday

Friday

Saturday

1

April Fool’s Day

2

5th Day of the Month

3

6th Day of the Month

4Rest

Qingming Festival

5Rest

8th Day of the Month

6Rest

9th Day of the Month

7

10th Day of the Month

8

11th Day of the Month

9

12th Day of the Month

10

13th Day of the Month

11

14th Day of the Month

12

15th Day of the Month

13

16th Day of the Month

14

17th Day of the Month

15

18th Day of the Month

16

19th Day of the Month

17

20th Day of the Month

18

21st Day of the Month

19

22nd Day of the Month

20

Grain Rain

21

24th Day of the Month

22

Earth Day

23

World Book Day

24

China Aerospace Day

25

28th Day of the Month

26

29th Day of the Month

27Class

30th Day of the Month

28

April

29

2nd Day of the Month

30

3rd Day of the Month

@秀米XIUMI

Cool Rain

Open Wisdom Station

C++ Competition Daily Problem - Day 704

Leave a Comment