O_Egor

J(4)

Sep 6th, 2022
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <string>
  6. #include <set>
  7. #include <map>
  8. #include <unordered_map>
  9. #include <iomanip>
  10. #include <string>
  11. using namespace std;
  12.  
  13. #define re return
  14. #define pb push_back
  15. #define eb emplace_back
  16. #define all(x) (x).begin(), (x).end()
  17. #define rall(x) (x).rbegin(), (x).rend()
  18. #define pi (3.14159265358979323846264338327950288419716939937510)
  19. #define unique(v) v.resize(unique(all(v)) - v.begin())
  20. #define bipbup ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  21.  
  22. typedef vector<int> vi;
  23. typedef vector<vi> vvi;
  24. typedef pair<int, int> ii;
  25. typedef vector<ii> vii;
  26. typedef vector<string> vs;
  27. typedef double D;
  28. typedef long double ld;
  29. typedef long long ll;
  30. typedef pair<ll, ll> pll;
  31. typedef vector<ll> vll;
  32. typedef unsigned long long ull;
  33.  
  34. void upperToLower(string& s)
  35. {
  36.     for (auto& i : s)
  37.         i = tolower(i);
  38.     re;
  39. }
  40.  
  41. int upperCounter(string& s)
  42. {
  43.     int counter(0);
  44.     for (auto& i : s)
  45.         if (isupper(i))
  46.             counter++;
  47.     re counter;
  48. }
  49.  
  50. bool isCorrect(string& s, string& C, string& D, set <string>& st)
  51. {
  52.     if (s == "")
  53.         re 0;
  54.     if (C == "no")
  55.         upperToLower(s);
  56.     if (st.find(s) != st.end())
  57.         re 0;
  58.     if (D == "no")
  59.         if (isdigit(s[0]))
  60.             re 0;
  61.     for (auto& i : s)
  62.         if (!isdigit(i))
  63.             re 1;
  64.  
  65.     re 0;
  66. }
  67.  
  68. void getWords(string& s, vs& words, string& C, string& D, set <string>& st)
  69. {
  70.     string word("");
  71.     for (auto& i : s)
  72.     {
  73.         if (isalpha(i) || isdigit(i) || i == '_')
  74.             word += i;
  75.         else
  76.         {
  77.             if (isCorrect(word, C, D, st))
  78.                 words.push_back(word);
  79.             word = "";
  80.         }
  81.     }
  82.     if (isCorrect(word, C, D, st))
  83.         words.push_back(word);
  84. }
  85. /*
  86. a12112 ASDSD _
  87. 121212a
  88. AS =as
  89. */
  90. int main()
  91. {
  92.     int n;
  93.     string C, D;
  94.     cin >> n >> C >> D;
  95.     set <string> st;
  96.     vs words;
  97.     unordered_map <string, ii> ans;
  98.     while (n--)
  99.     {
  100.         string s;
  101.         cin >> s;
  102.         if (C == "no")
  103.             upperToLower(s);
  104.         st.insert(s);
  105.     }
  106.     string s;
  107.  
  108.     while (getline(cin, s))
  109.     {
  110.         getWords(s, words, C, D, st);
  111.     }
  112.     int mx(0);
  113.     string ansWord;
  114.     //a a a b b b b
  115.     int pos = words.size() + 1;
  116.     for (int i = 0; i < (int)words.size(); ++i)
  117.     {
  118.         if(ans.find(words[i]) == ans.end())
  119.             ans[words[i]].second = i;
  120.         ans[words[i]].first++;
  121.         if (ans[words[i]].first > mx)
  122.         {
  123.             pos = ans[words[i]].second;
  124.             mx = ans[words[i]].first;
  125.             ansWord = words[i];
  126.         }
  127.         if(ans[words[i]].first == mx && ans[words[i]].second <= pos){
  128.             pos = ans[words[i]].second;
  129.             mx = ans[words[i]].first;
  130.             ansWord = words[i];
  131.         }
  132.     }
  133.     cout << ansWord;
  134.     re 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment