Created
November 27, 2011 16:50
-
-
Save yllan/1397805 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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