fork download
  1. #include "iostream"
  2. #include "string"
  3. #include "cstring"
  4. #include "cstdlib"
  5. #include "algorithm"
  6. #include "cstdio"
  7. using namespace std;
  8.  
  9. #define gc getchar_unlocked
  10.  
  11. void scanint(int &x)
  12. {
  13. register int c = gc();
  14. x = 0;
  15. for(;(c<48 || c>57);c = gc());
  16. for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
  17. }
  18.  
  19. int main(int argc, char const *argv[])
  20. {
  21. int t,q,i,j,c=0,h,x; string s;
  22. cin>>t;
  23. getline(cin,s);
  24. for(x=1;x<=t;x++)
  25. {cout<<"Case "<<x<<":"<<endl;
  26. string p,z;
  27. getline(cin,s);
  28. getline(cin,p);
  29. scanint(q);
  30.  
  31. while(q--)
  32. {
  33. scanint(i);scanint(j);c=0;z.clear();
  34. for(h=i;h<=j;h++)
  35. {
  36. if(s[h]==p[0])
  37. {
  38. if(p.length()==1)
  39. z=s.substr(h,p.length());
  40. else if(p.length()<=(j-h)+1)
  41. z=s.substr(h,p.length());
  42. if(!z.compare(p))
  43. {
  44. c++;h=h+p.length()-1;
  45. }
  46.  
  47. }
  48. }
  49. cout<<c<<endl;
  50. }
  51. }
  52.  
  53. return 0;
  54. }
  55.  
Success #stdin #stdout 0s 2824KB
stdin
2
cbaaabb
baaabb
3
0 7
0 2
1 0
ababababababaa ababa abab
b
3
0 24
0 0
4 5

stdout
Case 1:
1
0
0
Case 2:
10
0
1