blob: 220f02561c77e1d3c13a17c23c7031b4f01cf8ec (
plain)
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
|
#include <stdio.h>
/* remove s2 chars from s1 */
void
squeeze(char s1[], char s2[])
{
int i, j, k, b;
for (i = j = 0; s1[i] != '\0'; ++i) {
b = 0;
for (k = 0; s2[k] != '\0'; ++k) {
if (s1[i] == s2[k]) {
b = 1;
}
}
if (b == 0) {
s1[j++] = s1[i];
}
}
s1[j] = '\0';
}
/* return first index in s1 where any char in s2 */
int
any(char s1[], char s2[])
{
int i, j;
for (i = 0; s1[i] != '\0'; ++i) {
for (j = 0; s2[j] != '\0'; ++j) {
if (s1[i] == s2[j]) {
return i;
}
}
}
return -1;
}
int
main()
{
char s1[] = "foobar";
char s2[] = "a";
// squeeze(s1, s2);
printf("%d\n", any(s1, s2));
return 0;
}
|