hdu----(1075)What Are You Talking About(trie之查找)
What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 14107 Accepted Submission(s): 4546
is so lucky that he met a Martian yesterday. But he didn't know the
language the Martians use. The Martian gives him a history book of Mars
and a dictionary when it leaves. Now Ignatius want to translate the
history book into English. Can you help him?
problem has only one test case, the test case consists of two parts,
the dictionary part and the book part. The dictionary part starts with a
single line contains a string "START", this string should be ignored,
then some lines 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.
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
i like earth!
Huge input, scanf is recommended.
/*hdu 1075 字典树写法*/
//#define LOCAL
#include<cstdio>
#include<cstring>
#include<cstdlib>
typedef struct node
{
int id;
struct node *child[];
}Trie;
void Insert(char *s,Trie *root,int v)
{
Trie *cur=root,*curnew;
int i,pos;
for(i=;s[i]!='\0';i++){
pos=s[i]-'a';
if(cur->child[pos]==NULL)
{
curnew= new Trie;
curnew->id=;
for(int j=;j<;j++)
curnew->child[j]=NULL;
cur->child[pos]=curnew;
}
cur=cur->child[pos];
}
cur->id=v;
}
int query(char *s,Trie *root)
{
Trie *cur=root;
int i,pos;
for(i=;s[i]!='\0';i++){
pos=s[i]-'a';
if(cur->child[pos]!=NULL)
cur=cur->child[pos];
else return ; //输出原字符串
}
return cur->id;
}
char aa[][],bb[];
char str[];
int main()
{
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif
Trie *root= new Trie ;
root->id=;
int st;
for(int i=;i<;i++)
root->child[i]=NULL;
scanf("%s",aa[]);
int i=;
while(scanf("%s",aa[i]),strcmp(aa[i],"END"))
{
scanf("%s",bb);
Insert(bb,root,i); //对应标号
i++;
}
scanf("%s",aa[]);
getchar();
while(gets(str),strcmp(str,"END"))
{
for(st=i=;str[i]!='\0';i++)
{
if(str[i]<'a'||str[i]>'z'){
if(i>st){
strncpy(aa[],str+st,i-st);
aa[][i-st]='\0';
printf("%s",aa[query(aa[],root)]);
}
st=i+;
printf("%c",str[i]);
}
}
puts("");
}
return ;
}
当然可以用map,在这里就不在补充啦!喵喵!O(∩_∩)O哈哈~
hdu----(1075)What Are You Talking About(trie之查找)的更多相关文章
- HDU 1075 What Are You Talking About(Trie的应用)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- HDU 1075 What Are You Talking About (Trie)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- 题解报告:hdu 1075 What Are You Talking About
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 Problem Description Ignatius is so lucky that he ...
- hdu 1075 (map)
http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...
- hdu 1075 What Are You Talking About
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意:比较简单,易懂,这里不做说明. 解法:第一种方法:用map映射,耗时1000+ms:第二种 ...
- HDU 1057 What Are You Talking About trie树 简单
http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意 : 给一个单词表然后给一些单词,要求翻译单词表中有的单词,没有则直接输出原单词. 翻译文段部分get ...
- 字典树 HDU 1075 What Are You Talking About
http://acm.hdu.edu.cn/showproblem.php?pid=1075 ;}
- HDU 1075-What Are You Talking About(Trie)
题意: 给你一个字典 一个英文单词对应一个火星单词 给你一段火星文翻译成英文 字典上的没有的不翻译 分析: 没有给数据规模 字典树用链表 #include <map> #include & ...
- HDU 11488 Hyper Prefix Sets (字符串-Trie树)
H Hyper Prefix Sets Prefix goodness of a set string is length of longest common prefix*number of str ...
随机推荐
- 可是把ie67下面的bug改好了,其实很简单,ie67下面取出来的字符串是带有空格的,不知道为什么
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- C#中关键字ref修饰类对象或结构体[转]
using System; using System.Collections.Generic; using System.Text; namespace CSharpTest { struct Dog ...
- [Effective Java]第五章 泛型
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- FJNU 1152 Fat Brother And Integer(胖哥与整数)
FJNU 1152 Fat Brother And Integer(胖哥与整数) Time Limit: 1000MS Memory Limit: 257792K [Description] [题 ...
- NS_ASSUME_NONNULL_BEGIN,NS_ASSUME_NONNULL_END
Nonnull区域设置(Audited Regions) 如果需要每个属性或每个方法都去指定nonnull和nullable,是一件非常繁琐的事.苹果为了减轻我们的工作量,专门提供了两个宏:NS_AS ...
- style不同取值对应的日期、时间格式
from : http://www.cnblogs.com/Gavinzhao/archive/2009/11/10/1599690.html sql server2000中使用convert来取得d ...
- FTP常用故障代码注解
FTP错误列表 出处:http://bbs.enet.com.cn/UserControl?act=13&threadID 作者: |秒杀』| 详细的FTP错误列表 Restart marke ...
- 初始Hibernate框架技术
hibernate: 定义:ORM:Object Relational Mapping 对象 关系 映射 使用hibernate时几个必要的: 1.实体类 2.映射文件(类 -数据库表,属性-字段) ...
- C++大数类模板
友情提示:使用该模板的注意了,在大数减法里有一个小错误,导致减法可能会出错 // 原来的写法,将t1.len错写成了len ] == && t1.len > ) { t1.len ...
- bootstrap学习笔记<十>(按钮组,导航)
1)按钮组.样式:class="btn-group" <div class="btn-group"> <button class=" ...