Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <string>
- #include <unordered_map>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n;
- cin >> n;
- const string t = "BSUIROPENX";
- unordered_map<string, int> dict;
- vector<string> data(n);
- for (int i = 0; i < n; ++i) {
- cin >> data[i];
- }
- int64_t ans = 0;
- for (auto&& s : data) {
- auto pos = t.find(s);
- if (pos == 0) {
- string for_search = t.substr(s.length());
- if (t.length() > s.length() && dict.find(for_search) != dict.end()) {
- ans += dict[for_search];
- }
- dict[s]++;
- } else if (t.find(s) == t.length() - s.length()) {
- string for_search = t.substr(0, t.length() - s.length());
- if (t.length() > s.length() && dict.find(for_search) != dict.end()) {
- ans += dict[for_search];
- }
- dict[s]++;
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement