sahadat49

Untitled

Dec 14th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int a,b,ans=0,cnt=0;
  5. cin>>a>>b;
  6. string s,s1;
  7. cin>>s;
  8. char ch;
  9. map<char,int>mp;
  10. while(b--) {
  11. cin>>ch;
  12. mp[ch]=1;
  13. }
  14. vector<int>v;
  15. for(int i=0; i<a; i++) {
  16. if(mp[s[i]]==1) {
  17. v.push_back(1);
  18. } else
  19. v.push_back(0);
  20. }
  21.  
  22. for(int j=0; j<a; j++) {
  23. if(v[j]==1) {
  24. cnt++;
  25. }
  26. if(v[j]==0) {
  27. ans+=((cnt*(cnt+1))/2);
  28. cnt=0;
  29. }
  30. }
  31. cout<<ans<<endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment