Maruf_Hasan

String Naive

Oct 31st, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1.  
  2. //In the Name of Allah Most Gracious, Most Merciful//
  3. /*If you want something you've never had, you have to do something you never did.*/
  4.  
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7.  
  8.  
  9. #define pb push_back
  10. #define ll long long
  11. #define pii pair<int,int>
  12. #define pll pair<ll,ll>
  13. #define M 100007
  14. #define INF 1e9
  15. #define INFL 1e18
  16. #define PI acos(-1)
  17. #define mp make_pair
  18.  
  19. //const int fx[]= {+1,-1,+0,+0};
  20. //const int fy[]= {+0,+0,+1,-1};
  21. //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
  22. //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
  23. //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
  24. //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
  25.  
  26.  
  27.  
  28.  
  29.  
  30. int main()
  31. {
  32.  
  33. // #ifndef ONLINE_JUDGE
  34. // freopen("input.txt","r",stdin);
  35. // freopen("output.txt","w",stdout);
  36. // #endif
  37. string p,q;
  38. cin>>p>>q;
  39. int p_len=p.size();
  40. int q_len=q.size();
  41. int j=0;
  42. int flag=0;
  43. for(int i=0;i<=q_len-p_len;i++)
  44. {
  45. for(j=0;j<p_len;j++)
  46. {
  47. if(p[j]!=q[j+i])
  48. {
  49. break;
  50. }
  51. }
  52. if(j==p_len)
  53. {
  54. flag=1;
  55. cout<<"YES"<<endl;
  56. break;
  57. }
  58. }
  59. if(!flag)
  60. {
  61. cout<<"NO"<<endl;
  62. }
  63.  
  64.  
  65.  
  66. ///Before submit=>
  67. /// *check for integer overflow,array bounds
  68. /// *check for n=1
  69. }
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment