-
Notifications
You must be signed in to change notification settings - Fork 0
/
zipfslaw.cpp
78 lines (67 loc) · 1.46 KB
/
zipfslaw.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> pii;
map<string,int> ans;
void f(string s){
string tmp="";
for(int i=0;i<s.size();i++){
if(s[i]>='a'&&s[i]<='z')
tmp+=s[i];
else if(s[i]>='A'&&s[i]<='Z')
tmp+=(s[i]-'A'+'a');
else{
if(!tmp.empty()){
if(ans.count(tmp))
ans[tmp]++;
else
ans[tmp]=1;
tmp="";
}
}
}
if(!tmp.empty()){
if(ans.count(tmp))
ans[tmp]++;
else
ans[tmp]=1;
tmp="";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int n;
bool first=false;
while(cin>>n){
if(first)
cout<<'\n';
first=true;
string tmp;
ans.clear();
while(getline(cin,tmp)){
if(tmp=="EndOfText")
break;
f(tmp);
}
bool out = false;
for(auto it=ans.begin();it!=ans.end();it++){
if(it->second==n){
cout<<it->first<<'\n';
out=true;
}
}
if(out==false)
cout<<"There is no such word.\n";
}
return 0;
}