Skip to content

Commit 334fbb5

Browse files
authored
Create Q5.c
1 parent f6de997 commit 334fbb5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

W12/Q5.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
int main(void) {
5+
int i, j, n, m;
6+
scanf("%i %i ", &n, &m);
7+
char string1[n + 1], string2[n + 1];
8+
for (i = 0; i < n; i ++) {
9+
scanf("%c", &string1[i]);
10+
}
11+
string1[n] = '\0';
12+
13+
scanf(" ");
14+
15+
for (i = 0; i < m; i ++) {
16+
scanf("%c", &string2[i]);
17+
}
18+
string2[m] = '\0';
19+
20+
int count = 0;
21+
for (i = 0; i <= n - m; i ++) {
22+
count = count + 1;
23+
for (j = 0; j < m; j ++) {
24+
if (string1[i + j] != string2[j]) {
25+
count = count - 1;
26+
break;
27+
}
28+
}
29+
}
30+
31+
printf("%i", count);
32+
return 0;
33+
}

0 commit comments

Comments
 (0)