Skip to content

Instantly share code, notes, and snippets.

@yllan
Created November 27, 2011 16:50
Show Gist options
  • Select an option

  • Save yllan/1397805 to your computer and use it in GitHub Desktop.

Select an option

Save yllan/1397805 to your computer and use it in GitHub Desktop.
for (; *s; s++) t[*s]++;
void count(char *s, int t1, int t2, …, int t255)
{
if (*s == '\0') {
// output answer
} else if (*s == 1) {
count(str + 1, t1 + 1, t2, …, t255);
} else if (*s == 2) {
count(str + 1, t1, t2 + 1, …, t255);
} else if (*s == 3) {
// … omitted …
}
void derive_copy(int *origin, *int derived, int idx, int size, int pos, int value)
{
if (idx == size) return;
derived[idx] = (idx == pos) ? value : origin[idx];
derive-copy(origin, derived, idx + 1, size, pos, value);
}
int *derive(int *origin, int size, int pos, int value)
{
int *derived = (int *)malloc(sizeof(int) * size);
derive_copy(origin, derived, 0, size, pos, value);
return derived;
}
void count(char *s, int *t)
{
if (*s == '\0') {
// output answer
} else {
count(str + 1, derived(t, 256, *s, t[*s] + 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment