http://acm.hdu.edu.cn/showproblem.php?pid=1075

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 24477    Accepted Submission(s): 8237

Problem Description
Ignatius 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?
 
Input
The 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.
 
Output
In this problem, you have to output the translation of the history book.
 
Sample Input
START
from fiwo
hello difh
mars riwosf
earth fnnvk
like fiiwj
END
START
difh, i'm fiwo riwosf.
i fiiwj fnnvk!
END
 
Sample Output
hello, i'm from mars.
i like earth!

Hint

Huge input, scanf is recommended.

 
Author
Ignatius.L
 
Recommend
We have carefully selected several similar problems for you:  1800 1671 1247 1298 1026 
 
 
题目处理很恶心、、
 #include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdio>
#include <map> using namespace std; map<string,string>mmp;
char s[];
string a,b; int main()
{
cin>>a;
for(;cin>>a&&a!="END";)
cin>>b,mmp[b]=a;
cin>>a;
getchar();
for(int len;gets(s)&&strcmp(s,"END");)
{
len=strlen(s); a="";
for(int i=;i<len;i++)
if(islower(s[i])) a+=s[i];
else
{
if(mmp.find(a)!=mmp.end())
cout<<mmp[a];
else cout<<a;
a=""; cout<<s[i];
}
cout<<endl;
}
return ;
}

MAP——AC

 #include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cctype>
#include <cstdio> using namespace std; string a,b,ans;
char s[];
struct Trie
{
int next[];
string ans;
}tr[];
int tot; inline void Trie_build()
{
int now=,len=b.length();
for(int i=;i<len;i++)
{
int x=b[i]-'a';
if(tr[now].next[x])
now=tr[now].next[x];
else tr[now].next[x]=++tot,now=tot;
}
tr[now].ans+=a;
}
inline bool Trie_find()
{
int now=,p=;
int len=a.length();
for(;p<len;p++)
if(tr[now].next[a[p]-'a'])
now=tr[now].next[a[p]-'a'];
else return ;
ans=tr[now].ans;
if(!ans.length()) return ;
return ;
} int main()
{
cin>>a;
for(;cin>>a&&a!="END";)
cin>>b,Trie_build();
cin>>a;
getchar();
for(int len;gets(s)&&strcmp(s,"END");)
{
len=strlen(s); a="";
for(int i=;i<len;i++)
if(islower(s[i])) a+=s[i];
else
{
if(Trie_find()) cout<<ans;
else cout<<a; ans="";a="";
cout<<s[i];
}
memset(s,,sizeof(s));
cout<<endl;
}
return ;
}

Trie树——AC

HDU——T 1075 What Are You Talking About的更多相关文章

  1. 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 ...

  2. hdu 1075 (map)

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 What Are You Talking About Time Limit: 10000/5000 MS ...

  3. hdu 1075 What Are You Talking About

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 题意:比较简单,易懂,这里不做说明. 解法:第一种方法:用map映射,耗时1000+ms:第二种 ...

  4. 字典树 HDU 1075 What Are You Talking About

    http://acm.hdu.edu.cn/showproblem.php?pid=1075 ;}

  5. 题解报告:hdu 1075 What Are You Talking About

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1075 Problem Description Ignatius is so lucky that he ...

  6. 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 ...

  7. hdu 1075:What Are You Talking About(字典树,经典题,字典翻译)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  8. hdu 1075 二分搜索

    还是写一下,二分搜索好了 这道题开数组比较坑... 二分,需要注意边界问题,例如:左闭右闭,左闭右开,否则查找不到or死循环 先上AC代码 #include<iostream> #incl ...

  9. HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)

    Problem Description Ignatius is so lucky that he met a Martian yesterday. But he didn't know the lan ...

随机推荐

  1. hdu_5154 拓扑

    #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...

  2. 51nod-1296: 有限制的排列

    [传送门:51nod-1296] 简要题意: 有一个集合,集合中的数为1到n 给出a限制条件,a[i]表示第a[i]位置的数要比相邻位置的数要小 给出b限制条件,b[i]表示第b[i]位置的数要比相邻 ...

  3. bzoj4873: [Shoi2017]寿司餐厅(最大权闭合子图)

    4873: [Shoi2017]寿司餐厅 大难题啊啊!!! 题目:传送门 题解:一眼题是网络流,但还是不会OTZ,菜啊... %题解... 最大权闭合子图!!! 好的...开始花式建边: 1.对于每个 ...

  4. rest_framework 分页三种

    .分页 a. 分页 看第n页 每页显示n条数据: b. 分页 在某个位置 向后查看多少条数据 c. 加密分页 上一页和下一页 本质:查看 记住页码id的最大值和最小值 通过其来准确扫描 过去的话 会从 ...

  5. python-网络-tcp

    python-网络-tcp 标签(空格分隔): python TCP[client]-发送数据 from socket import * s = socket(AF_INET, SOCK_STREAM ...

  6. 关于iOS适配问题

    大家都知道在iOS开发当中对于UI适配问题可以从如下两个方面去考虑: 1.比例适配 2.利用autolayout自动布局 通常情况来说,利用auto自动布局是一个比较好的方案,开发者可以利用story ...

  7. dedecms4张关键表解析之1

    虽然dedecms默认共有87张表,但是只有4张最核心,最最要的表. 1.第一张表:dede_arctype  栏目表 dede设计者认为不管存放什么样的数据(文章,商品,电影)都应该属于某个栏目(类 ...

  8. form表单提交的时候,传过去的值是键值对的形式

    效果展示 第一种需求,点击input的时候,input的value发生改变 $('.group-wrapper input').click(function(){ $(this).val(0); // ...

  9. python第三次作业——叶耀宗

    作业1 import random#引入随机数模块xing=["小白","小黄","小王","小陈","小绿& ...

  10. 紫书 习题 10-8 UVa 10622(gcd)

    把这个数质因数分解然后求因子个数的gcd就ok了. 一些细节 (1)这道题的质因数不需要存下来,每一次做完取一次gcd就ok了 (2)判断奇偶用ans & 1的时候要加括号, 位运算要注意括号 ...