Created
January 20, 2019 17:21
-
-
Save cbdavide/68b6e961bf641d67a52279d5464232f9 to your computer and use it in GitHub Desktop.
UVa 10126 - Zipf's Law
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define F first | |
#define S second | |
#define endl '\n' | |
#define PB push_back | |
typedef long long ll; | |
typedef vector<ll> vll; | |
typedef pair<int, int> ii; | |
typedef vector<ii> vii; | |
typedef vector<int> vi; | |
const int oo = ~(1<<31); | |
int main() { | |
#ifndef CBDAVIDES | |
ios_base::sync_with_stdio(false); | |
cin.tie(NULL); | |
#endif | |
int n, idx=0; | |
string s; | |
vector< vector<string> > sol; | |
while(cin >> n) { | |
map<string, int> T; | |
while(cin >> s) { | |
if(s == "EndOfText") { | |
idx++; | |
break; | |
} | |
string w = ""; | |
for(char c : s) { | |
if(islower(c) || isupper(c)) w.PB(tolower(c)); | |
else { | |
if(w != "")T[w]++; | |
w = ""; | |
} | |
} | |
if(w != "") T[w]++; | |
} | |
vector<string> tmp; | |
for(auto p : T) | |
if(p.S == n) tmp.PB(p.F); | |
sol.PB(tmp); | |
} | |
for(int i=0; i<sol.size(); i++) { | |
if(i) cout << endl; | |
if(!sol[i].size()) cout << "There is no such word." << endl; | |
else for(string t : sol[i]) cout << t << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment