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 ...
随机推荐
- Create Function
示例,创建一个名为HelloWorld4的函数,不需要输入参数 CREATE FUNCTION HelloWorld4()RETURNS VARCHAR(20)ASBEGINRETURN 'Hello ...
- Walkthrough: Arranging Controls on Windows Forms Using Snaplines
https://msdn.microsoft.com/en-us/library/t5b5kc41(v=vs.110).aspx Spacing and Aligning Controls Using ...
- 巧遇"drwxr-xr-x."权限
drwxr-xr-x. 是SELinux的问题 REDHAT6之后安全提高所以设置的 关闭SELINUX就好了 因为新版本ls把多acl和selinux属性加进去了,与系统无关,新版本的ls代码使用1 ...
- T-SQL over()函数在单个表中的聚合
Sales.OrderValues是一个视图,在这里作为测试表. 现在想实现,每个订单的数据行新增两个列,totalvalue(所有订单的总金额),custtotalvalue(当前订单的custid ...
- 在CSS中,BOX的Padding属性的数值赋予顺序为
4种可能的情况,举例说明: padding:10px; // 四个内边距都是10px padding:5px 10px; // 上下5px 左右10px padding:5px 10px 15px; ...
- 泛型IComparer<T>排序
class Program { static void Main(string[] args) { GetListTest(); } private static void GetListTest() ...
- iOS - UITabBarController
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITabBarController : UIViewController <UITabBarDelegate ...
- ubuntu_常用命令_01
1. 获取超级用户权限(需要输入超级用户的密码) sudo -i 2. 文本编辑器(暂时觉得 类似Windows里面的txt,更多功能有待发现) gedit /xxx/yyy ZC: 貌似 这个命令 ...
- css 常用样式命名规则
大家在写css的时候,对一些html标签起一个合适的名字是个很头疼的事情,现在给大家分享项目中常用的名字供参考. 外套:wrap ——用于最外层 头部:header ——用于头部 主要内容:mai ...
- hdu5785(极角排序求所有锐角钝角个数)
做法很显然,求出所有的锐角和钝角就能求出有多少个锐角三角形了. 我用了愚钝的方法,写了两三个小时... 看了下别人简单的代码.学习了下做法. sort(temp+,temp+cnt+);//排序 Fo ...