hdu1075What Are You Talking About(Trie tree)
来源:互联网 发布:注册域名需要哪些手续 编辑:程序博客网 时间:2024/05/15 08:38
晚上A一题,睡的香~@Albafica大牛
睡觉前再水一发字典树:
->题目请戳这里<-
题目大意:有个火星人,写了一段火星文,都看不懂,但是留下了一本字典,要求翻译。能翻译的翻译,不能翻译的直译~
题目分析:字典树字典树~
详情请见代码:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;typedef struct node{ struct node *next[26]; char s[11]; bool tag;}tree;char s1[3001],s2[3001];void init(tree *t){ memset(t->s,0,sizeof(t->s)); for(int i = 0;i < 26;i ++) t->next[i] = NULL; t->tag = 0;}void build(tree *t,int id){ if(t->next[s2[id] - 'a'] == NULL) { t->next[s2[id] - 'a'] = (tree *)malloc(sizeof(tree)); init(t->next[s2[id] - 'a']); } if(s2[id + 1]) build(t->next[s2[id] - 'a'],id + 1); else { strcpy(t->next[s2[id] - 'a']->s,s1); t->next[s2[id] - 'a']->tag = 1; }}int find(tree *t,int id){ if(t->next[s2[id] - 'a'] == NULL) return 0; if(s2[id + 1] == '\0')//到了查找的单词末尾 { if(t->next[s2[id] - 'a']->tag)//如果字典中也查到了末尾,即查到 { printf("%s",t->next[s2[id] - 'a']->s); return 1; } return 0;//要查找的单词短了,即没找到 } return find(t->next[s2[id] - 'a'],id + 1);}int main(){ int i,j; tree *root = NULL; scanf("%s",s1); root = (tree *)malloc(sizeof(tree)); init(root); while(scanf("%s",s1),strcmp(s1,"END") != 0) { s1[strlen(s1)] = '\0'; scanf("%s",s2); s2[strlen(s2)] = '\0'; build(root,0); } //scanf("%s",s1); gets(s1); gets(s1); //printf("s1:%s\n",s1); while(gets(s1),strcmp(s1,"END") != 0) { //printf("s11:%s\n",s1); for(i = 0;s1[i];i ++) { if(!islower(s1[i])) putchar(s1[i]); else { j = 0; while(islower(s1[i])) s2[j ++] = s1[i ++]; i --; s2[j] = '\0'; if(!find(root,0)) printf("%s",s2); j = 0; } } printf("\n"); } return 0;}//468MS59932K
- hdu1075What Are You Talking About(Trie tree)
- hdu1075What Are You Talking About(字典树)
- hdu1075What Are You Talking About (字典树)
- hdu1075What Are You Talking About(map容器)
- hdu1075What Are You Talking About(字典树,map)
- HDU -- 1075 What Are You Talking About(Trie 树)
- HDU 1075 What Are You Talking About (Trie)
- What Are You Talking About(trie树或map)
- HDU1075 What Are You Talking About(trie树)
- HDOJ 1075 -- What Are You Talking About Trie( STL )
- hdu 1075 What Are You Talking About Trie树
- HDU1075(What are you talking about)--Trie树练习
- HDU 1075 What Are You Talking About Trie题解
- hdu 1075 What Are You Talking About 字典树 trie
- HDU 1075 What Are You Talking About Trie
- hdu 1075 What Are You Talking About ( trie + 模拟 )
- HDOJ-1075What Are You Talking About(Trie/Map)
- hdu 1075 What Are You Talking About(Trie树)
- C语言面向对象的实现---封装性
- iOS网络编程实践--蓝牙对等网络通信实例讲解
- C语言面向对象的实现---继承性
- 一点一点的改变
- HTML5 history API 介绍
- hdu1075What Are You Talking About(Trie tree)
- C语言面向对象的实现---多态性
- PM 如何使自己的观点有说服力,让技术人员觉得你说得有道理,愿意按你说的做
- 嵌入式系统专业 要学的课程
- linux下安装ActiveMQ
- Shell脚本初步学习-鸟哥Linux私房菜基础学习篇
- CppUnit测试框架入门
- ubuntu下安装配置Django
- woj 1012 滚动数组