hdu1075 字典树
来源:互联网 发布:梦幻群侠传3优化版攻略 编辑:程序博客网 时间:2024/05/01 23:38
题意即把火星文翻译成英文,先给出对应关系,然后输入要查询的火星文
首先还是构造字典树,把火星文存进去,不同的是在每个节点开一个存字符串的数组,每存完一段火星文都把对应的英文存在最后那个结点
然后查询的时候分情况,标点符号直接输出,其他的到query函数去查,如果后面没有了,输出后返回,如果有对应单词,输出对应dic,如果没有输出本身
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<string>using namespace std;struct node{ char dic[15]; node * next[26]; bool flag;}*root;node *build(){ node *p=(node *)malloc(sizeof(node)); for(int i=0;i<26;i++) p->next[i]=NULL; p->flag=false; return p;}void insert(char *earth,char *mars){ int len=strlen(mars); node *p; p=root; for(int i=0;i<len;i++) { if(p->next[mars[i]-'a']==NULL) p->next[mars[i]-'a']=build(); p=p->next[mars[i]-'a']; } p->flag=true; strcpy(p->dic,earth);}void query(char *earth){ int len=strlen(earth); node *p; p=root; for(int i=0;i<len;i++) { if(p->next[earth[i]-'a']==NULL) { printf("%s",earth); return; } p=p->next[earth[i]-'a']; } if(p->flag) printf("%s",p->dic); else printf("%s", earth);}int main(){ char earth[15],mars[15],ask[3010]; scanf("%s",earth); root=build(); while(scanf("%s",earth),strcmp(earth,"END")) { scanf("%s",mars); insert(earth,mars); } scanf("%s",earth); getchar(); while(gets(ask),strcmp(ask,"END")) { int len=strlen(ask); for(int i=0;i<len;i++) { if(islower(ask[i])) { int j=0; memset(earth,'\0',sizeof(earth)); while(islower(ask[i])) earth[j++]=ask[i++]; query(earth); } if(!islower(ask[i])) printf("%c",ask[i]); } printf("\n"); } return 0;}
0 0
- hdu1075--还是字典树
- HDU1075 字典树
- hdu1075之字典树
- hdu1075 字典树
- hdu1075 字典树
- 字典树hdu1075
- hdu1075 字典树
- hdu1075字典树解法
- HDU1075 字典树
- hdu1075 字典树
- 字典树(hdu1075)
- hdu1075(字典树入门)
- hdu1075 字典树
- hdu1247+hdu1075 字典树基础
- 字典树 ZOJ1109 HDU1251 PKU1204 HDU1075
- HDU1075-字符串映射-字典树&map
- HDU1075静态数组实现字典树
- hdu1075 What Are You Talking About-字典树
- hdu 3418 Beautiful Dream数学题
- 杭电ACM 1398 Square Coins(母函数)
- POJ1159 Palindrome 【动态规划】
- 第一篇。
- jdk与jre的区别
- hdu1075 字典树
- spring mvc和spring的区别
- java学习课堂笔记2
- leetcode Gas Station
- 怎么建立win7无线热点
- 杭电1233还是畅通工程
- spring事务管理
- hdu-oj 1302 The Snail
- [水]ZOJ1241