13a1t
オ #include <stdlib.h>
エ #include "trie.h"
イ #define SIZE 26
ウ struct trie { int val; triep child[SIZE]; };
カ triep trie_new() {
ニ int i;
テ triep p = (triep)malloc(sizeof(struct trie));
ネ p->val = -1;
サ for(i = 0; i < 26; ++i) { p->child[i] = NULL; }
フ return p;
ケ }
ク void trie_put(triep p, char *s, int v) {
シ if(*s == '\0') {
ノ p->val = v;
タ } else if('a' <= *s && *s <= 'z') {
ナ int i = *s - 'a';
セ if(p->child[i] == NULL) {
ヌ p->child[i] = trie_new();
ケ }
ホ trie_put(p->child[i], s+1, v);
ケ }
ケ }
キ int trie_get(triep p, char *s) {
シ if(*s == '\0') {
ヒ return p->val;
タ } else if('a' <= *s && *s <= 'z') {
ナ int i = *s - 'a';
セ if(p->child[i] == NULL) {
ハ return -1;
ケ }
ヘ return trie_get(p->child[i], s+1);
ケ }
ケ }
----------
オ #include <stdlib.h>
エ #include "trie.h"
イ #define SIZE 26
ウ struct trie { int val; triep child[SIZE]; };
カ triep trie_new() {
テ triep p = (triep)malloc(sizeof(struct trie));
ニ int i;
ネ p->val = -1;
サ for(i = 0; i < 26; ++i) { p->child[i] = NULL; }
フ return p;
ケ }
ク void trie_put(triep p, char *s, int v) {
シ if(*s == '\0') {
ノ p->val = v;
タ } else if('a' <= *s && *s <= 'z') {
ナ int i = *s - 'a';
セ if(p->child[i] == NULL) {
ヌ p->child[i] = trie_new();
ケ }
ホ trie_put(p->child[i], s+1, v);
ケ }
ケ }
キ int trie_get(triep p, char *s) {
シ if(*s == '\0') {
ヒ return p->val;
タ } else if('a' <= *s && *s <= 'z') {
ナ int i = *s - 'a';
セ if(p->child[i] == NULL) {
ハ return -1;
ケ }
ヘ return trie_get(p->child[i], s+1);
ケ }