fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define f(i,x,y) for(long long i = (x);i < (y);++i)
  4. #define MOD 1000000007
  5.  
  6.  
  7. int main()
  8. {
  9. int T;
  10. cin >> T;
  11. while(T--)
  12. {
  13. string txt,pat;
  14. cin >> txt >> pat;
  15. int n = txt.size(),m = pat.size();
  16. int arr[m];
  17. map<char,int> mp;
  18. map<char,int> ::iterator it;
  19. f(i,0,m)
  20. {
  21. mp[pat[i]] = i;
  22. arr[i] = 0;
  23. }
  24.  
  25. for(int i = (n-1);i > -1;i--)
  26. {
  27. char ch = txt[i];
  28. if(mp.find(ch) != mp.end())
  29. {
  30. int j = mp[ch];
  31. if(j == (m-1))
  32. arr[j]++;
  33. else if(j < (m-1))
  34. arr[j] += arr[j+1];
  35. else
  36. {;}
  37. }
  38. }
  39. //f(i,0,m)
  40. //cout << arr[i] << "-";
  41. cout <<arr[0] << endl;
  42. }
  43. }
Success #stdin #stdout 0s 3476KB
stdin
3
3141592653 123
Banana ban
GeeksforGeeks Ge
stdout
2
0
6