Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <algorithm>
- #include <cmath>
- #include <string>
- #include <set>
- #include <map>
- #include <unordered_map>
- #include <iomanip>
- #include <string>
- using namespace std;
- #define re return
- #define pb push_back
- #define eb emplace_back
- #define all(x) (x).begin(), (x).end()
- #define rall(x) (x).rbegin(), (x).rend()
- #define pi (3.14159265358979323846264338327950288419716939937510)
- #define unique(v) v.resize(unique(all(v)) - v.begin())
- #define bipbup ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef pair<int, int> ii;
- typedef vector<ii> vii;
- typedef vector<string> vs;
- typedef double D;
- typedef long double ld;
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef vector<ll> vll;
- typedef unsigned long long ull;
- void upperToLower(string& s)
- {
- for (auto& i : s)
- i = tolower(i);
- re;
- }
- int upperCounter(string& s)
- {
- int counter(0);
- for (auto& i : s)
- if (isupper(i))
- counter++;
- re counter;
- }
- bool isCorrect(string& s, string& C, string& D, set <string>& st)
- {
- if (s == "")
- re 0;
- if (C == "no")
- upperToLower(s);
- if (st.find(s) != st.end())
- re 0;
- if (D == "no")
- if (isdigit(s[0]))
- re 0;
- for (auto& i : s)
- if (!isdigit(i))
- re 1;
- re 0;
- }
- void getWords(string& s, vs& words, string& C, string& D, set <string>& st)
- {
- string word("");
- for (auto& i : s)
- {
- if (isalpha(i) || isdigit(i) || i == '_')
- word += i;
- else
- {
- if (isCorrect(word, C, D, st))
- words.push_back(word);
- word = "";
- }
- }
- if (isCorrect(word, C, D, st))
- words.push_back(word);
- }
- /*
- a12112 ASDSD _
- 121212a
- AS =as
- */
- int main()
- {
- int n;
- string C, D;
- cin >> n >> C >> D;
- set <string> st;
- vs words;
- unordered_map <string, ii> ans;
- while (n--)
- {
- string s;
- cin >> s;
- if (C == "no")
- upperToLower(s);
- st.insert(s);
- }
- string s;
- while (getline(cin, s))
- {
- getWords(s, words, C, D, st);
- }
- int mx(0);
- string ansWord;
- //a a a b b b b
- int pos = words.size() + 1;
- for (int i = 0; i < (int)words.size(); ++i)
- {
- if(ans.find(words[i]) == ans.end())
- ans[words[i]].second = i;
- ans[words[i]].first++;
- if (ans[words[i]].first > mx)
- {
- pos = ans[words[i]].second;
- mx = ans[words[i]].first;
- ansWord = words[i];
- }
- if(ans[words[i]].first == mx && ans[words[i]].second <= pos){
- pos = ans[words[i]].second;
- mx = ans[words[i]].first;
- ansWord = words[i];
- }
- }
- cout << ansWord;
- re 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment