Advertisement
paranid5

Vsesib3

Oct 18th, 2020
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(nullptr);
  10.     cout.tie(nullptr);
  11.    
  12.     string input;
  13.     cin >> input;
  14.  
  15.     int n = 0;
  16.     cin >> n;
  17.  
  18.     vector<pair<string, int>> str(n);
  19.  
  20.     for (auto& i : str)
  21.         cin >> i.first >> i.second;
  22.  
  23.     int64_t ans = 0;
  24.  
  25.     for (int i = 0; i < input.size(); i++)
  26.     {
  27.         for (const auto& s : str)
  28.         {
  29.             if (s.first.size() > i + 1)
  30.                 continue;
  31.            
  32.             bool find = true;
  33.  
  34.             for (int q = 0; q < s.first.size(); q++)
  35.             {
  36.                 if (input[i - s.first.size() + q + 1] != s.first[q])
  37.                 {
  38.                     find = false;
  39.                     break;
  40.                 }
  41.             }
  42.  
  43.             if (find)
  44.                 ans += s.second;
  45.         }
  46.     }
  47.  
  48.     cout << ans;
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement