fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin>>t;
  7. while(t--){
  8. int z;
  9. cin>>z;
  10. string s;
  11. cin>>s;
  12. char tt;
  13. cin>>tt;
  14. long long sum=0;
  15. long long sum1=0;
  16. //int count=0;
  17. int j=0;
  18. int n=z;
  19. sum=(n*(2+(n-1)))/2;
  20. //cout<<sum<<endl;
  21. for(int i=0;i<z;i++){
  22. if(s[i]==tt){
  23. sum1+=(j*(2+(j-1)))/2;
  24. j=0;
  25. }
  26. else{
  27. j++;
  28. }
  29.  
  30.  
  31. }
  32. sum-=sum1;
  33. cout<<sum<<endl;
  34.  
  35. }
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 4520KB
stdin
1
5
cacac c
stdout
13