AF
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
C
#include <stdio.h>
#include <memory.h>
#define MAX_STRING 256
int main() {
char s[] ="ababac";
int lcps[MAX_STRING];
for (int i=0; i<strlen(s); i++) {
lcps[i] = 0;
if (s[i] == s[0]) {
lcps[i]++;
}
for (int j=0; j<i; j++) {
if (lcps[j] == i && s[i] == s[lcps[j]]) {
lcps[j]++;
} else if (lcps[j] > 0) {
if(s[i] == s[lcps[j]] && (j+lcps[j]) >= i) {
lcps[j]++;
}
}
}
}
for(int i = 0; i < strlen(s); i++) {
printf("len(LCP(s(%d,%d),s)) = %d\n", i, strlen(s), lcps[i]);
}
return 0;
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Try this
- AF December 05, 2018