Advertisement
Shuva_Dev

Subsequence string or not

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