-
Notifications
You must be signed in to change notification settings - Fork 0
/
I M07 - Discover the Substring.c
67 lines (60 loc) · 1.02 KB
/
I M07 - Discover the Substring.c
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
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
char s1[101],s2[101];
int i,c=0,j,m,n,p=0;
scanf("%s%s",s1,s2);
m=strlen(s1);
n=strlen(s2);
i=0;
if(m==n)
{
if(!strcmp(s1,s2))
c++;
}
else if(m>n)
{
i=0;
for(i=0;i<=m-n;i++)
{
j=0;
p=0;
while(s2[j])
{
if(s1[i+j]!=s2[j])
{
p=1;
break;
}
j++;
}
if(p==0)
c++;
}
}
else
{
i=0;
for(i=0;i<=n-m;i++)
{
j=0;
p=0;
while(s1[j])
{
if(s2[i+j]!=s1[j])
{
p=1;
break;
}
j++;
}
if(p==0)
c++;
}
}
printf("%d",c);
return 0;
}