Created
January 19, 2014 05:04
-
-
Save kavinyao/8500659 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int overlap_count(const char *s1, const char *s2) | |
{ | |
const char *s1_begin = s1; | |
const char *p1, *p2; | |
while(*s1_begin != '\0') { | |
p1 = s1_begin; | |
p2 = s2; | |
while(*p1 != '\0' && *p2 != '\0' && *p1 == *p2) { | |
p1++; | |
p2++; | |
} | |
if(*p1 == '\0') | |
return p1 - s1_begin; | |
s1_begin++; | |
} | |
return 0; | |
} | |
int main(int argc, char **argv) { | |
if(argc < 3) { | |
printf("Not enough input.\n"); | |
return 1; | |
} | |
printf("Overlapping size = %d\n", overlap_count(argv[1], argv[2])); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment