HDU 1075 What Are You Talking About
2012-01-12 14:53
465 查看
HDU_1075
为了练习一下字典树所以做了一下这个题目。由于题目数据比较多,数组开小了会WA。
为了练习一下字典树所以做了一下这个题目。由于题目数据比较多,数组开小了会WA。
#include<stdio.h> #include<string.h> #include<ctype.h> #define MAXD 500010 char str[30], b[30], txt[3010], word[MAXD][12]; int flag[MAXD], p[MAXD], next[MAXD][26], w, e; void insert(int cur, int k) { ++ e; flag[e] = 0; memset(next[e], 0, sizeof(next[e])); next[cur][k] = e; } void init() { int i, j, k, cur; w = e = 0; memset(next[e], 0, sizeof(next[e])); gets(b); for(;;) { gets(b); if(strcmp("END", b) == 0) break; sscanf(b, "%s%s", word[++ w], str); cur = 0; for(i = 0; str[i]; i ++) { k = str[i] - 'a'; if(!next[cur][k]) insert(cur, k); cur = next[cur][k]; } flag[cur] = 1; p[cur] = w; } } int find() { int i, j, k, cur; cur = 0; for(i = 0; str[i]; i ++) { k = str[i] - 'a'; if(!next[cur][k]) return 0; cur = next[cur][k]; } if(!flag[cur]) return 0; printf("%s", word[p[cur]]); return 1; } void solve() { int i, j, k; gets(b); for(;;) { gets(txt); if(strcmp(txt, "END") == 0) break; for(i = 0; txt[i]; i ++) { if(isalpha(txt[i])) { for(j = 0; isalpha(txt[i]); j ++, i ++) str[j] = txt[i]; str[j] = '\0'; if(!find()) printf("%s", str); -- i; } else printf("%c", txt[i]); } printf("\n"); } } int main() { init(); solve(); return 0; }
相关文章推荐
- HDU 1075 What Are You Talking About(用map进行翻译)
- hdu1075——What Are You Talking About
- HDU 1075 What Are You Talking About (字典树)
- hdu 1075 What Are You Talking About map
- HDU 1075 What Are You Talking About (字符串处理)
- HDU 1075 What Are You Talking About
- hdu-1075 What Are You Talking About
- HDU 1075 What Are You Talking About(字典树)
- HDU 1075 What Are You Talking About
- HDU 1075 What Are You Talking About
- hdu 1075 What Are You Talking About(给你字典,让你翻译句子,字典中查不到的单词不用翻译)
- 【字典树】hdu 1075 What Are You Talking About
- hdu 1075 What Are You Talking About (字典树)
- HDU 1075——What Are You Talking About(Trie树)
- HDU-1075 What Are You Talking About(map)
- hdu 1075 What Are You Talking About(map)
- hdu 1075 What Are You Talking About(字典树)
- HDU-1075 What Are You Talking About (STL:map)
- hdu 1075 What Are You Talking About 字典树
- HDU_1075 What Are You Talking About(Trie 树)