HDU_1804_Deli Deli (字典树)
来源:互联网 发布:运城淘宝店长招聘网 编辑:程序博客网 时间:2024/06/06 04:34
http://acm.hdu.edu.cn/showproblem.php?pid=1804
#include <stdio.h>#include <string.h>const int words_max_length = 23; //单词的最大长度,题目给的是20struct node{node * child[26];char word[words_max_length];node(){memset(child, 0, sizeof(child)); memset(word, 0, sizeof(word));}}* root = new node(); // 先建立一个全局的根结点void add_word(char * before, char * after){//往字典树中加入数据,before是要检索的单词,after是最终结点中的数据,也就是对应不规则单词的复数形式node * next = root;while(*before){if(next->child[*before-'a'] == NULL)next->child[*before-'a'] = new node();next = next->child[*before-'a'];before++;}strcpy(next->word, after);}char * query(char * str){//查询不规则复数单词表,返回的是单词的首地址,如果没有,返回空node * next = root;while(*str){if(next->child[*str-'a'] == NULL)return NULL;next = next->child[*str-'a'];str++;}return next->word;}int main(){//freopen("E:\\input.txt", "r", stdin);int n, m;scanf("%d %d", &n, &m);char before[words_max_length], after[words_max_length];while(n--){scanf("%s %s", before, after);add_word(before, after);}while(m--){scanf("%s", before);int len = strlen(before);char * sptr = query(before);//strcpy(after, query(before));if(sptr != NULL)printf("%s\n", sptr);else if( (before[len-1] == 'y') && (before[len-2] != 'a' && before[len-2] != 'e' && before[len-2] != 'i' && before[len-2] != 'o' && before[len-2] != 'u') ){before[len-1] = 'i';printf("%ses\n", before);}else if( (before[len-1]=='o') || (before[len-1]=='s') || (before[len-1]=='x') || (!strcmp(&before[len-2], "ch")) || (!strcmp(&before[len-2], "sh")) )printf("%ses\n", before);elseprintf("%ss\n", before);}return 0;}
- HDU_1804_Deli Deli (字典树)
- [字典树] HDU 1804 - Deli Deli
- HDU 1804 Deli Deli (String)
- Deli Deli
- HDU 1804 Deli Deli
- poj 3366 Deli Deli
- hdu_1804 Deli Deli
- HDU1804 Deli Deli
- UVa 11233 - Deli Deli
- HDU 1804 Deli Deli
- BNUOJ 1010 Deli Deli
- HDU 1804:Deli Deli
- HDU_1804Deli Deli
- 【TOJ 2911】 Deli Deli【水题】
- POJ 3366 Deli Deli 可能会
- 【端午小练】HDU1804-Deli Deli
- HDU——1804 Deli Deli
- 杭电OJ 1803 Deli Deli
- delphi XE2中安装ehlib5.6
- 使用Bash进行Socket通信
- 排序(四)——关于归并排序
- 用Javascript实现让Canvas变模糊的效果
- APP widget初学 (一)
- HDU_1804_Deli Deli (字典树)
- 在Android中使用ContentResolver查询系统数据库时使用外键查询与distinct的小技巧
- android号码匹配位数修改
- VC判断窗口最小化或最大化函数
- DEV 通过配置工具可以不用 pause 语句暂停
- ORA-24399:invalid number of connections specified
- 触发器
- python的自动化测试模块
- SQLite学习手册(数据表和视图)