finding the subsequence of a string !

 #include <iostream>

#include <cstring>

#include <algorithm>

using namespace std;

void subArray(string s1,string s){

bool flag = false;

int size = s.size();

for(int i = 0;i<size;i++){

for(int j = i;j<size;j++){

for(int k = i;k<=size;k++){

cout << s.substr(k) << endl;

if(s.substr(k,1)== s1){

flag = true;

break;

}

}

}

}

if(flag == true){

cout << "YES";

} else {

cout << "NO";

}

}

int main(){

string main = "hello",sub;

cin >> sub;

subArray(main,sub);

return 0;

}

Comments