Created
September 20, 2012 09:48
-
-
Save raptium/3754981 to your computer and use it in GitHub Desktop.
string
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
int s(char *str, int len) { | |
int i, j; | |
int sum = 0; | |
int *count = (int *)malloc(sizeof(int) * len); | |
char *k = (char *)malloc(sizeof(char) * len); | |
memset(count, 0, sizeof(int) * len); | |
memset(k, 1, sizeof(char) * len); | |
for(i = 0;i < len;i++) { | |
char ch = str[i]; | |
for(j = 0;j <= i;j++) { | |
if(k[j]) { | |
if(ch == str[i-j]){ | |
count[j]++; | |
} else { | |
k[j]=0; | |
} | |
} | |
} | |
if(ch == str[0]) { | |
count[i] = 1; | |
} | |
} | |
for(i = 0;i < len;i++) { | |
sum += count[i]; | |
} | |
free(count); | |
free(k); | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment