Advertisement
Josif_tepe

Untitled

Mar 3rd, 2022
1,176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     string A, B;
  10.     int repeat;
  11.     cin >> A >> B >> repeat;
  12.    
  13.    
  14.     string s = "";
  15.     for(int i = 0; i < repeat; i++) {
  16.         s += A;
  17.         if(A.size() > 0) {
  18.             A.erase(A.end() - 1);
  19.         }
  20.     }
  21.     vector<bool> alpha(26, false);
  22.     for(int i = 0; i < B.size(); i++) {
  23.         alpha[B[i] - 'a'] = true;
  24.     }
  25.     int result = 0;
  26.    
  27.     for(int i = 0; i < s.size(); i++) {
  28.         int sum = 0;
  29.         for(int j = i; j < s.size(); j++) {
  30.             sum += alpha[s[j] - 'a'];
  31.             result += sum;
  32.         }
  33.     }
  34.     cout << result << endl;
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement