hdu1075What Are You Talking About(字典树)

题目链接:hdu1075

/*hdu 1075 What Are You Talking About(字典树) 题目大意: 每行输入两个单词,第二个单词可以翻译成第一个单词。 给出一串字符,能翻译的输出翻译后的单词,不能的原样输出。 思路:字典树 */ #include #include #include #include #include #include using namespace std; bool flag; struct node { bool flag; char str[15]; node *next[26]; }*root; node *build()//建立结点 { node *p = (node *)malloc(sizeof(node)); for(int i = 0; i next[i] = NULL; p -> flag = false; return p; } void save(char *a, char *s) { int len = strlen(s); node *p; p = root; for(int i = 0; i next[s[i] - 'a'] == NULL) p -> next[s[i] - 'a'] = build(); p = p -> next[s[i] - 'a']; } p -> flag = true;//标记,单词的最后一个字符 strcpy(p -> str, a);//在该结点将翻译后的单词存下 } void query(char *s) { int len = strlen(s); node *p; p = root; for(int i = 0; i next[s[i] - 'a'] == NULL) { printf("%s",s); return; } p = p -> next[s[i] - 'a']; } if(p -> flag)//单词能被翻译 printf("%s", p -> str); else printf("%s", s); } int main() { char s1[15],s2[15],ss[3005]; scanf("%s",s1); root = build(); while(scanf("%s",s1), strcmp(s1, "END")) { scanf("%s",s2); save(s1, s2); } scanf("%s",s1); getchar(); while(gets(ss), strcmp(ss, "END")) { int len = strlen(ss); for(int i = 0; i

点击复制链接 与好友分享!回本站首页
您对本文章有什么意见或着疑问吗?请到论坛讨论您的关注和建议是我们前行的参考和动力
上一篇:UVA - 11997 K Smallest Sums
下一篇:SRM 609 D2L3: VocaloidsAndSongs,dp
相关文章

HDU 1075(What Are You Talking

hdu 1075 What Are You Talking

hdu 1075 What Are You Talking

hdu 1075 What Are You Talking

A little thought about .NET Fr

NYOJ-219 An problem about date

HDU 4910 Problem about GCD(米勒

图文推荐

hdu1075What Are You Talking About(字典树)
ZOJ 3640 Help Me
hdu1075What Are You Talking About(字典树)
CF 518C(Anya and
hdu1075What Are You Talking About(字典树)
hdu 1016 Prime R
UVA - 11987 - A

分类:默认分类 时间:2015-03-11 人气:2
本文关键词:
分享到:

相关文章

Copyright (C) quwantang.com, All Rights Reserved.

趣玩堂 版权所有 京ICP备15002868号

processed in 0.043 (s). 10 q(s)