Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <string>
  5. #include <unordered_map>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.     ios_base::sync_with_stdio(false);
  11.     cin.tie(0);
  12.     int n;
  13.     cin >> n;
  14.     const string t = "BSUIROPENX";
  15.  
  16.     unordered_map<string, int> dict;
  17.     vector<string> data(n);
  18.     for (int i = 0; i < n; ++i) {
  19.         cin >> data[i];
  20.     }
  21.     int64_t ans = 0;
  22.     for (auto&& s : data) {
  23.         auto pos = t.find(s);
  24.         if (pos == 0) {
  25.             string for_search = t.substr(s.length());
  26.             if (t.length() > s.length() && dict.find(for_search) != dict.end()) {
  27.                 ans += dict[for_search];
  28.             }
  29.             dict[s]++;
  30.         } else if (t.find(s) == t.length() - s.length()) {
  31.             string for_search = t.substr(0, t.length() - s.length());
  32.             if (t.length() > s.length() && dict.find(for_search) != dict.end()) {
  33.                 ans += dict[for_search];
  34.             }
  35.             dict[s]++;
  36.         }
  37.     }
  38.     cout << ans;
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement