Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <map>
- #include <deque>
- #include <queue>
- #include <set>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <iomanip>
- #include <stack>
- typedef long long ll;
- typedef long double ld;
- const int N = int(1e5) + 111;
- const int INF = int(1e9) + 111;
- const ll LINF = ll(1e18) + 111;
- const ld EPS = 1e-7;
- const ld PI = 3.141592653589793238462643;
- const ll MOD = ll(1e9) + 7;
- #define pb push_back
- #define all(v) v.begin(), v.end()
- #define sz(v) v.size()
- #define x first
- #define y second
- #define watch(el) cout << #el << " " << el << endl;
- using namespace std;
- template<typename T> inline istream &operator >> (istream &in, vector<T> &v) { for (auto &i : v) { in >> i; } return in; }
- template<typename T> inline ostream &operator<< (ostream &out, const vector<T> &v) { for (auto &it : v) { out << it << " "; } return out; }
- template<typename T, typename F> inline ostream &operator<< (ostream &out, const map<T, F> &v) { for (auto &it : v) { out << "(" << it.first << ":" << it.second << ") "; } return out; }
- bool num, reg;
- set<string> keywords;
- int timer = 0;
- map<string, pair<int,int>> mp;
- bool isInd(string s) {
- bool f = 0;
- for (char c : s)
- f |= (!isdigit(c));
- return f && !(isdigit(s[0]) && !num);
- }
- string norm(string s) {
- string res;
- for (char &c : s) {
- if (isalnum(c) || c == '_')
- if (!reg && isalpha(c))
- res += tolower(c);
- else
- res += c;
- else
- if (!res.empty() && res.back() != ' ')
- res += ' ';
- }
- return res;
- }
- vector<string> split(string &s) {
- vector<string> res;
- if (s.back() != ' ')
- s += " ";
- auto pr = string::npos;
- auto space = s.find(" ", 0);
- while (space != string::npos) {
- string t = s.substr(pr + 1, space - pr -1);
- res.pb(t);
- pr = space;
- space = s.find(" ", space + 1);
- }
- return res;
- }
- void counter(string s) {
- s = norm(s);
- if (s == "" || s == " ") return;
- vector<string> v(split(s));
- for (auto t : v) {
- if (!keywords.count(t) && isInd(t)) {
- if (mp.count(t))
- mp[t].second++;
- else
- mp[t] = { timer++,1 };
- }
- }
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- ifstream cin("input.txt");
- //ofstream cout("output.txt");
- int n;
- string s;
- cin >> n;
- cin >> s;
- reg = s == "yes";
- cin >> s;
- num = s == "yes";
- for (int i = 0; i < n; i++) {
- cin >> s;
- if (!reg)
- s = norm(s);
- keywords.insert(s);
- }
- getline(cin, s);
- while (getline(cin, s)) {
- counter(s);
- }
- int maxim = 0, l = 0;
- string ans;
- for (auto el : mp) {
- if (el.second.second > maxim)
- ans = el.first, maxim = el.second.second, l = el.second.first;
- else
- if (el.second.second == maxim && el.second.first < l)
- ans = el.first, maxim = el.second.second, l = el.second.first;
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement