Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <map>
  5. #include <deque>
  6. #include <queue>
  7. #include <set>
  8. #include <cmath>
  9. #include <string>
  10. #include <algorithm>
  11. #include <iomanip>
  12. #include <stack>
  13. typedef long long ll;
  14. typedef long double ld;
  15. const int N = int(1e5) + 111;
  16. const int INF = int(1e9) + 111;
  17. const ll LINF = ll(1e18) + 111;
  18. const ld EPS = 1e-7;
  19. const ld PI = 3.141592653589793238462643;
  20. const ll MOD = ll(1e9) + 7;
  21. #define pb push_back
  22. #define all(v) v.begin(), v.end()
  23. #define sz(v) v.size()
  24. #define x first
  25. #define y second
  26. #define watch(el) cout << #el << " " << el << endl;
  27. using namespace std;
  28. template<typename T> inline istream &operator >> (istream &in, vector<T> &v) { for (auto &i : v) { in >> i; } return in; }
  29. template<typename T> inline ostream &operator<< (ostream &out, const vector<T> &v) { for (auto &it : v) { out << it << " "; } return out; }
  30. 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; }
  31.  
  32. bool num, reg;
  33. set<string> keywords;
  34.  
  35. int timer = 0;
  36. map<string, pair<int,int>> mp;
  37.  
  38. bool isInd(string s) {
  39.     bool f = 0;
  40.     for (char c : s)
  41.         f |= (!isdigit(c));
  42.     return f && !(isdigit(s[0]) && !num);
  43. }
  44.  
  45. string norm(string s) {
  46.     string res;
  47.     for (char &c : s) {
  48.         if (isalnum(c) || c == '_')
  49.             if (!reg && isalpha(c))
  50.                     res += tolower(c);
  51.                 else
  52.                     res += c;
  53.         else
  54.             if (!res.empty() && res.back() != ' ')
  55.                 res += ' ';
  56.     }
  57.     return res;
  58. }
  59.  
  60. vector<string> split(string &s) {
  61.     vector<string> res;
  62.     if (s.back() != ' ')
  63.         s += " ";
  64.     auto pr = string::npos;
  65.     auto space = s.find(" ", 0);
  66.     while (space != string::npos) {
  67.         string t = s.substr(pr + 1, space - pr -1);
  68.         res.pb(t);
  69.         pr = space;
  70.         space = s.find(" ", space + 1);
  71.     }
  72.     return res;
  73. }
  74.  
  75. void counter(string s) {
  76.     s = norm(s);
  77.     if (s == "" || s == " ") return;
  78.     vector<string> v(split(s));
  79.     for (auto t : v) {
  80.         if (!keywords.count(t) && isInd(t)) {
  81.             if (mp.count(t))
  82.                 mp[t].second++;
  83.             else
  84.                 mp[t] = { timer++,1 };
  85.         }
  86.     }
  87. }
  88.  
  89. int main() {
  90.     ios_base::sync_with_stdio(0);
  91.     cin.tie(0);
  92.     ifstream cin("input.txt");
  93.     //ofstream cout("output.txt");
  94.     int n;
  95.     string s;
  96.     cin >> n;
  97.     cin >> s;
  98.     reg = s == "yes";
  99.     cin >> s;
  100.     num = s == "yes";
  101.     for (int i = 0; i < n; i++) {
  102.         cin >> s;
  103.         if (!reg)
  104.             s = norm(s);
  105.         keywords.insert(s);
  106.     }
  107.     getline(cin, s);
  108.     while (getline(cin, s)) {
  109.         counter(s);
  110.     }
  111.     int maxim = 0, l = 0;
  112.     string ans;
  113.     for (auto el : mp) {
  114.         if (el.second.second > maxim)
  115.             ans = el.first, maxim = el.second.second, l = el.second.first;
  116.         else
  117.             if (el.second.second == maxim && el.second.first < l)
  118.                 ans = el.first, maxim = el.second.second, l = el.second.first;
  119.     }
  120.     cout << ans;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement