kennnn
BAN USER#include <stdio.h>
#include <string.h>
// return 0 if success
int match(char *s1, char *s2, char *s3) {
if(!s3)
return 0;
if (s1[0] && s2[0]) {
if (s1[0] != s2[0]){
if (s1[0] != s3[0] && s2[0] != s3[0]) {
return 1;
} else if (s1[0] == s3[0]) {
return match(&s1[1], s2, &s3[1]);
} else
return match(s1, &s2[1], &s3[1]);
} else {
return match(s1, &s2[1], &s3[1]) & match(&s1[1], s2, &s3[1]);
}
} else if (!s1[0]) {
if (!strcmp(s2, s3))
return 0;
return 1;
} else {
if (!strcmp(s1, s3))
return 0;
return 1;
}
}
int main() {
char a[5] = {'a', 'm', 'n', '\0', '\0'};
char b[4] = {'a', 'y', 'z', '\0'};
char c[8] = {'a', 'm', 'n', 'a', 'y', 'z', '\0', '\0'};
int ret = match(a, b, c);
printf("ret: %d\n", ret);
}
a recursive method, not O(n) if conflict exists
- kennnn November 12, 2012
@ kkr.ashish, " the number n-2^k has to be as beautiful as n", therefore, A cannot change "10011" to "1111"
- kennnn October 30, 2013