-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpword.c
65 lines (54 loc) · 1.07 KB
/
pword.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int pword(const char *sub, const char *str) {
int i = 0;
int j = 0;
int tmpj;
int subLen = strlen(sub);
//int strLen = strlen(str);
while (str[j]) {
if (i == subLen)
i = 0;
//printf("1 i = %d j = %d\n", i, j);
if (sub[i] == str[j]) {
i++;
j++;
//printf("2 i = %d j = %d\n", i, j);
} else if (sub[0] == str[j]) {
i = 1;
j++;
//printf("3 i = %d j = %d\n", i, j);
} else {
int k;
for (k = 0; k < subLen; k++) {
i = 0;
tmpj = j - (1 + k);
//printf("tmp = %d\n", tmpj);
while (sub[i] == str[tmpj] && tmpj < j + 1) {
i++;
tmpj++;
}
//printf("tmp = %d i = %d\n", tmpj, i);
if ((tmpj - 1) == j) {
i = 0;
j -= (1 + k);
//printf(" tmp = j = %d\n", tmpj);
break;
}
}
if (k == subLen){
return 0;
//printf("k = subLen = %d\n", k);
}
}
}
return 1;
}
int main(int argc, char **argv) {
const char *sub = argv[1];
const char *str = argv[2];
(pword(sub, str)) ? printf("yes") : printf("no");
printf("\n");
return 0;
}