-
Notifications
You must be signed in to change notification settings - Fork 0
/
strincl.cpp
63 lines (63 loc) · 1.54 KB
/
strincl.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
#include <bits/stdc++.h>
using namespace std;
/*Informations
This program is created by XiaoYi Zero on ASUS Vivobook Pro 16
You can FREELY spread it base on GNU Public License.
by XiaoYi Zero OpenSource Software Movement.
*/
int main()
{
char str1[20], str2[20], temp[20];
int i=0, start=0, length2=0, posi, q=0, verify=0;
bool firstinclude;
cout<<"Give me two strings, if the second string is included in the first string, I will tell you the start of the second string."<<endl;
scanf("%s", str1);
scanf("%s", str2);
while(str1[i]!='\0')
{
if(str1[i]==str2[0])
{
firstinclude=1;
start=i;
}
i++;
}
i=0;
if(firstinclude==1)
{
while(str2[i]!='\0')
{
i++;
}
length2=i;
i=start;
posi= start + length2;
while(i<posi)
{
temp[q]=str1[i];
q++;
i++;
}
i=0;
while(str2[i]!='\0')
{
if(str2[i]==temp[i]) verify++;
i++;
}
if(verify==length2)
{
cout<<"The second string is included in the first string, the start of it was the "<<start<<" digit of the first string."<<endl;
return 0;
}
else
{
cout<<"The second string isn't included in the first string."<<endl;
return 0;
}
}
else
{
cout<<"The second string isn't included in the first string."<<endl;
return 0;
}
}