Print number of matching sequence in the user given input for the constant input.

I wrote a code to get the number of sequences occurring in the user input sequence.
This is my code. It excludes the subsequence which I wish to be tested.
I need to consider 12,23,34,123,234,1234 as sequences.
Overlapping of sequences should not be considered (12 in 123 should not be considered).
For e.g. constant number 1234
User given number 124312341211423
Output : No.of Sequence found 4
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
 #include<iostream>
#include<string>
#include<cstring>

using namespace std;

int main()
{
string num1;
string seq;
cout << "Enter constant number: ";
cin >> num1;
cout << "Enter the sequence: ";
cin >> seq;
int count=0;
for (int t=0; t<=num1.size()-2; t++)
{
string num = num1;
for (int k = num1.size(); k>=2-t ;k--)
{
cout << num <<"\n";
if (t==2 && k<=2)
break;
//num=num.substr(t,t+k-1);
for (int j = 1; seq.find(num) != string::npos; j++)
{
seq = seq.substr(0,seq.find(num)) + " " + seq.substr(seq.find(num)+num.size());
count = count + 1;
}
num = num.substr(t,t+k-1);
}
cout<< seq << "\n";
}
cout << "No. of sequences found: " << count << "\n";
return 0;
}
Topic archived. No new replies allowed.