1825. Nickname
Constraints
Time Limit: 3 secs, Memory Limit: 32 MB
Description
ZSUQ Messenger is similar with Tencent QQ. Each user will make a nickname for itself. Different users can have identical nickname. Some common ones, such as “Tom”, “Marry”, “Kate”, are frequently used. In a recent survey, the ZSUQ Company was astonished to find that there are no more than 5000 distinct nicknames that are being used.
Being a member of the ZSUQ Company, you are asked to make a report, telling the number of users for each nick name. A complete list of all users’ nicknames is provided to you. Please note that nicknames are case insensitive.
Input
The first line of the file contains an integer indicating the number of test cases.
In each test case, there is an integer N in the first line (0 < N
< 100,000). The following N lines describe N users’ nicknames. Each name consists of no more than 100 characters. There is a bland line between two cases.
Output
For each case, give out a list of the distinct nickname, one per line, followed by a bland space and the number of users who has this nickname. The names are in alphabetic order. There is no bland space at the beginning or the end of each line. Nicknames should be presented in lowercase letter. There is a bland line after each case.
Sample Input
1 4 carp inkfish peipei carp
Sample Output
carp 2 inkfish 1peipei 1
#include <algorithm> #include <iostream> #include <string> #include <stdio.h> #include <queue> #include <string.h> #include <vector> #include <iomanip> #include <map> #include <stack> #include <functional> #include <list> #include <cmath> using namespace std; map<string, int> m; int main() { std::ios::sync_with_stdio(false); int caseNum; cin >> caseNum; while (caseNum--) { m.clear(); int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; for (int j = 0; j < s.size(); j++) if ('A' <= s[j] && s[j] <= 'Z') s[j] += 32; if (m.find(s) == m.end()) m[s] = 1; else m[s]++; } for (map<string, int>::iterator iter = m.begin(); iter != m.end(); iter++) cout << iter->first << " " << iter->second << endl; cout << endl; } //getchar(); //getchar(); return 0; }