Advertisement
Shuva_Dev

Check substring or not (Easy)

Dec 11th, 2022
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define endl "\n"
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     string s1, s2 = "hello";
  8.     cin >> s1;
  9.  
  10.     int i=0, j=0;
  11.  
  12.     while(i<s1.size() && j<s2.size()) {
  13.         if(s1[i] == s2[j]) {
  14.             j++;
  15.         }
  16.  
  17.         i++;
  18.     }
  19.     if(j==s2.size()) cout << "YES";
  20.     else cout << "NO";
  21.    
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement