给出一篇英文文章,现在需要统计文章中出现英文单词的数量。
输入格式:
第一行一个T,代表数据组数
对于每组数据,第一行一个n,代表文章中单词的个数,其后n行每行一个只包含小写字母的长度为1到10的字符串
输出格式:
每组数据输出若干行,每行输出单词以及它出现的次数(中间空格隔开),不同单词按单词字典序从小到大输出
保证单词出现的总次数<=1e5
输入样例:
1
8
it
is
a
pen
it
is
a
dog
输出样例:
a 2
dog 1
is 2
it 2
pen 1
代码长度限制
16 KB
时间限制
1000 ms
内存限制
64 MB
栈限制
8192 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
int t,n;
cin>>t;
while(t--){
cin>>n;
multiset<string> s;
while(n--){
string word;
cin>>word;
s.insert(word);
}auto it1=s.begin();
if(it1!=s.end())cout<<*it1<<" "<<s.count(*it1)<<endl;
for(auto it=s.begin();it!=s.end();it++){
if(*it!=*it1){
cout<<*it<<" "<<s.count(*it)<<endl;
it1=it;
}
}
}
return 0;
}