Skip to content

Instantly share code, notes, and snippets.

@raptium
Created September 20, 2012 09:48
Show Gist options
  • Save raptium/3754981 to your computer and use it in GitHub Desktop.
Save raptium/3754981 to your computer and use it in GitHub Desktop.
string
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