fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. int main()
  6. {
  7. int t;
  8. //cin>>t;
  9. //for(int i=0;i<t;i++)
  10. // {
  11. int textlen;
  12. int patrnlen;
  13. //cin >> textlen; //input text string size
  14. //cin >> patrnlen; //input pattern string size
  15.  
  16. string text="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB";
  17. string patrn="AAAB";
  18. //cin >> text; //input text string
  19. //cin >> patrn; // input pattern string
  20.  
  21. textlen = text.size();
  22. patrnlen = patrn.size();
  23.  
  24. int flag=0;
  25. int cnt=0;
  26.  
  27.  
  28. for(int i = 0;i < textlen;)
  29. { //cout<<i;cnt++;
  30. int rght = 0;
  31. int lft = 0;
  32. if(patrn[0] == text[i] && patrn[patrnlen-1] == text[i+patrnlen-1])
  33. { //cout<<"a";
  34. int mid;
  35. mid = patrnlen/2;
  36. if(patrn[mid] == text[i+mid])
  37. {
  38. for(int x = mid + i,j = mid;x < patrnlen + i && j < patrnlen;x ++, j++)
  39. {
  40. if(text[x] != patrn[j])
  41. break;
  42. if(j == patrnlen - 1)
  43. rght = 1;
  44. }
  45. for(int x = i,j = 0;x <= i + mid ;x++,j++)
  46. {
  47. if(text[x] != patrn[j] && rght)
  48. {
  49. i += patrnlen;
  50. break;
  51. }
  52. if(mid == j && rght == 1)
  53. lft=1;
  54. }
  55. //cout<<rght<<" "<<lft<<"\n";
  56. if(lft && rght)
  57. flag = 1;
  58. }
  59.  
  60. }
  61. i++;
  62. if(flag) break;
  63. }
  64. if(flag)
  65. cout<<"yes"<<endl;
  66. else
  67. cout<<"no"<<endl;
  68. }
  69.  
  70.  
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
yes