diff --git a/Q5(i).cpp b/Q5(i).cpp index 2753fe4..7c85860 100644 --- a/Q5(i).cpp +++ b/Q5(i).cpp @@ -1,94 +1,68 @@ -#include +using namespace std; #include +#include #include -#include -using namespace std; - -bool check( vector text ,vector pattern){ - long text_size = text.size(); // size of text vector - long pattern_size = pattern.size(); // size of pattern vector - if( text_size < pattern_size ) { - // if size of pattern is greater than size of text , then it's not possible to search pattern in text. so return false +bool check_subsequence(vector A,vector B) +{ + int m=A.size(); + int n=B.size(); + if(m text; - ifstream myfile1 ("text_file.txt"); - if ( myfile1 ) { - string line; - while ( getline (myfile1 , line) ) { - string temp = ""; - for(int i = 0; i < line.length(); ++i) { - if( line.substr(i,3).compare(" , ") != 0) { // getting ' , ' then store it - temp += line[i]; - } - else { - text.push_back(temp); - temp = ""; - i = i + 2; - } - - } +int main() +{ + vector a; + vector b; + cout<<"Enter events A:"; + bool acontinue=true; + do + { + string atemp; + getline(cin,atemp); + if(!atemp.compare("exit"))//type exit to stop + { + acontinue=false; } - myfile1.close(); - } - else { - cout << "\nUnable to open text file\n"; - } - - // reading from pattern_file.txt and storing it in pattern vector - vector pattern; - ifstream myfile2 ("pattern_file.txt"); - if (myfile2) { - string line; - while ( getline (myfile2 , line) ) { - string temp = ""; - for(int i = 0; i < line.length(); ++i) { - if( line.substr(i,1).compare(" , ") != 0) { // getting ' , ' then store it - temp += line[i]; - } - else { - pattern.push_back(temp); - temp = ""; - i = i + 2; - } - - } + else + a.push_back(atemp); + }while(acontinue); + + cout<<"Enter events B:"; + bool bcontinue=true; + do + { + string btemp; + getline(cin,btemp); + if(!btemp.compare("exit")) + { + bcontinue=false; } - myfile2.close(); - } - else { - cout << "\nUnable to open pattern file\n"; - } - if( check( text , pattern ) ) { - cout<<"\nText contains Pattern\n"; - } - else { - cout<<"\nText does not contain Pattern\n"; - } + else + b.push_back(btemp); + }while(bcontinue); + + if(check_subsequence(a,b)) + cout<<"\nyes,list of events b is a subsequence of events b"; + else + cout<<"no"; + return 0; }