-
Notifications
You must be signed in to change notification settings - Fork 0
/
subsequence.cpp
83 lines (75 loc) · 1.42 KB
/
subsequence.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <iostream>
#include <string>
#include <ctype.h>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
vector<string> s;
char ch='y';
do
{
string temp;
cin>>temp;
s.push_back(temp);
cout<<" y or n : ";
cin>>ch;
cout<<endl;
}while(ch=='y'||ch=='Y');
vector<string>::iterator i;
for ( i = s.begin() ; i < s.end() ; ++i )
{
cout << *i << endl;
}
vector<string> s1;
char ch1='y';
do
{
string temp;
cin>>temp;
s1.push_back(temp);
cout<<" y or n : ";
cin>>ch1;
cout<<endl;
}while(ch1=='y'||ch1=='Y');
vector<string>::iterator j;
for ( j = s1.begin() ; j < s1.end() ; ++j )
{
cout << *j << endl;
}
i=s.begin();
j=s1.begin();
vector<string> k;
while(i<s.end() && j<s1.end())
{
string temp1=*i;
string temp2=*j;
if(temp1.compare(temp2)==0)
{
k.push_back(temp1);
i=i+1;
j=j+1;
}
else
{
i=i+1;
}
}
if(!k.empty())
{
cout<<"/nSubsequence Found ";
vector<string>::iterator p;
for (p = k.begin() ; p < k.end() ; ++p )
{
cout << *j << endl;
}
}
else
{
cout<<"/nSubsequence Not Found ";
}
return 0;
}