hdu1075What Are You Talking About (字典树)
into English. Can you help him?
follow, each line contains two strings, the first one is a word in English, the second one is the corresponding word in Martian's language. A line with a single string "END" indicates the end of the directory part, and this
string should be ignored. The book part starts with a single line contains a string "START", this string should be ignored,
then an article written in Martian's language.
You should translate the article into English with the dictionary.
If you find the word in the dictionary you should translate it and write the new word into your translation,
if you can't find the word in the dictionary you do not have to translate it, and
just copy the old word to your translation. Space(' '), tab('\t'), enter('\n') and all the punctuation should not be translated. A line with a single string "END" indicates the end of the book part, and that's also the end
of the input. All the words are in the lowercase, and each word will contain at most 10 characters, and each line will contain at most 3000 characters.
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
hello, i'm from mars.
i like earth! [hint]
Huge input, scanf is recommended.
[/hint]#include<stdio.h>
#include<string.h>
#include<malloc.h>
typedef struct nnn
{
int flag;
char *traslat;
struct nnn *next[26];
}node;
node *builde()
{
node *p=(node*)malloc(sizeof(node));
p->flag=0;
for(int i=0;i<26;i++)
p->next[i]=NULL;
return p;
}
node *root;
void insert(char str[],char tras[])
{
node *p=root;
for(int i=0;str[i]!='\0';i++)
{
if(p->next[str[i]-'a']==NULL)
p->next[str[i]-'a']=builde();
p=p->next[str[i]-'a'];
}
p->flag=1;
int len=strlen(tras)+1;
p->traslat=(char*)malloc(len*sizeof(char));
strcpy(p->traslat,tras);
}
void trasl(char str[])
{
node *p=root;
for(int i=0;str[i]!='\0';i++)
{
if(p->next[str[i]-'a']==NULL)
{
printf("%s",str); return ;
}
p=p->next[str[i]-'a'];
}
if(p->flag)
printf("%s",p->traslat);
else
printf("%s",str);
}
int main()
{
char tras[15],str[3005],str1[15];
root=builde();
while(scanf("%s",tras)>0&&strcmp(tras,"END")!=0)
{
if(strcmp("START",tras)==0)continue;
scanf("%s",str);
insert(str,tras);
}
getchar();
while(gets(str),strcmp(str,"END")!=0)
{
if(strcmp("START",str)==0)continue;
int len=strlen(str);
for(int i=0,j=0;i<=len; i++)
{
if(str[i]>='a'&&str[i]<='z')
str1[j++]=str[i];
else
{
str1[j]='\0';
if(j) trasl(str1);
if(i==len||str[i]=='\n')printf("\n");
else if(str[i]=='\t') printf("\t");
else printf("%c",str[i]);
j=0;
}
}
}
}
hdu1075What Are You Talking About (字典树)的更多相关文章
- 萌新笔记——用KMP算法与Trie字典树实现屏蔽敏感词(UTF-8编码)
前几天写好了字典,又刚好重温了KMP算法,恰逢遇到朋友吐槽最近被和谐的词越来越多了,于是突发奇想,想要自己实现一下敏感词屏蔽. 基本敏感词的屏蔽说起来很简单,只要把字符串中的敏感词替换成"* ...
- [LeetCode] Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Note:You may assume that all inputs ar ...
- 字典树+博弈 CF 455B A Lot of Games(接龙游戏)
题目链接 题意: A和B轮流在建造一个字,每次添加一个字符,要求是给定的n个串的某一个的前缀,不能添加字符的人输掉游戏,输掉的人先手下一轮的游戏.问A先手,经过k轮游戏,最后胜利的人是谁. 思路: 很 ...
- 萌新笔记——C++里创建 Trie字典树(中文词典)(一)(插入、遍历)
萌新做词典第一篇,做得不好,还请指正,谢谢大佬! 写了一个词典,用到了Trie字典树. 写这个词典的目的,一个是为了压缩一些数据,另一个是为了尝试搜索提示,就像在谷歌搜索的时候,打出某个关键字,会提示 ...
- 山东第一届省赛1001 Phone Number(字典树)
Phone Number Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 We know that if a phone numb ...
- 字典树 - A Poet Computer
The ACM team is working on an AI project called (Eih Eye Three) that allows computers to write poems ...
- trie字典树详解及应用
原文链接 http://www.cnblogs.com/freewater/archive/2012/09/11/2680480.html Trie树详解及其应用 一.知识简介 ...
- HDU1671 字典树
Phone List Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- *HDU1251 字典树
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
随机推荐
- webform--常用的控件
一.简单控件 1.Lable——标签:在网页中呈现出来的时候会变成span标签 属性:Text——标签上的文字 BackColor,ForeColor——背景色,前景色 Font——字体 Bold- ...
- java操作Excel处理数字类型的精度损失问题验证
java操作Excel处理数字类型的精度损失问题验证: 场景: CELL_TYPE_NUMERIC-->CELL_TYPE_STRING--->CELL_TYPE_NUMERIC POI版 ...
- JAVA之等号、传类对象参数与c++的区别
在JAVA中用等号对类对象进行赋值,实际上操作的是对象的地址. eg: package MyText; class ClassA { int value; public void seta(int v ...
- POJ 3090 Visible Lattice Points 欧拉函数
链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,而且这些点与(0,0)的连点不经过其它的点. 思路:显而易见, ...
- Amlogic开关机按键功能实现
在做AMlogic项目的时候,配置按键后,发现电源键仅仅能关机,不能开机,非常是郁闷 后来发现是漏掉了一个地方没有配置,firmware/arc_power/irremote2arc.c 这个文件中面 ...
- EF 简单的 CRUD、分页 代码笔记
添加: static void Main(string[] args) { CCDBEntities ccdbContext = new CCDBEntities( ...
- C++如何屏蔽双击运行程序功能?
问题描述: 我们开发过程中可能会经常遇到,需要屏蔽EXE的双击运行功能,只能通过宿主程序(Service或EXE)来启动.比如腾讯的迷你弹窗,就只能通过主程序来启动,而不能直接通过双击来运行. 实现原 ...
- Jquery Mobile转场特效之slide | 小小iPhone开发
Jquery Mobile转场特效之slide | 小小iPhone开发 2012 Jquery Mobile转场特效之slide 作者:小小 发布:2012-12-12 14:03 分类:j ...
- [cocos2d-x]HelloWorldDemo
实现一个demo,具备以下功能: 1.让几个字分别位于中间和四个角落. 2.中间的字体改变,并且带有闪烁功能. 3.单点触摸和多点触摸,并且能够实现滑动效果,滑动的话必须使用带有bool返回值的单点触 ...
- 屏蔽EditText长按导致的弹出输入法的对话框
做了个能手动拖动的EditText,但有个问题导致的体验很不好,就是手放上去开始拖,拖到一段距离后弹出个输入法的对话框,这根本不是我想要的效果,于是就想屏蔽它,结果在网上找到一句代码,放上去 顿时解决 ...