HDU——T 1075 What Are You Talking About
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
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.
#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的更多相关文章
- 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 (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 1075 What Are You Talking About
http://acm.hdu.edu.cn/showproblem.php?pid=1075 ;}
- 题解报告: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 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(字典树,经典题,字典翻译)
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- hdu 1075 二分搜索
还是写一下,二分搜索好了 这道题开数组比较坑... 二分,需要注意边界问题,例如:左闭右闭,左闭右开,否则查找不到or死循环 先上AC代码 #include<iostream> #incl ...
- 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 ...
随机推荐
- 2、java注释、标识符、数据类型、类型转换
一.三种注释:单行注释.多行注释.文档注释(只能在类前或者方法前,@author作者) 二.java使用的编码为unicode码[0-65535] 包含ASCII码,在0-255中 ASCII码( ...
- Google浏览器怎样删除指定网址的网址提示
方法例如以下: Windows系统:按键盘上的"箭头下".按shift+delete(或者shift+回退): Mac系统:按fn+shift+delete. (此方法不须要清空b ...
- BAPC2014 K&&HUNNU11591:Key to Knowledge(中途相遇法)
题意: 有N个学生.有M题目 然后相应N行分别有一个二进制和一个整数 二进制代表该同学给出的每道题的答案.整数代表该同学的答案与标准答案相符的个数 要求推断标准答案有几个,假设标准答案仅仅有一种.则输 ...
- Find or Query Data with C# Driver
https://docs.mongodb.com/getting-started/csharp/query/ Overview You can use the Find and FindAsync m ...
- 面向对象(OOP)五大基本原则
书单 <Object-Oriented Analysis & Design with Application>:Grady Booch, 下载地址:object-oriented- ...
- vue组件的一些知识理解
组件我们在项目中会很常用到,说下自己在学习过程中的理解,有关 组件初始化顺序,组件为什么data是function,组件的生命周期 1. Vue.component('', {}) 注册全局组件,组 ...
- 1893. [国家集训队2011]等差子序列(bitset)
★★ 输入文件:nt2011_sequence.in 输出文件:nt2011_sequence.out 简单对比时间限制:0.3 s 内存限制:512 MB [试题来源] 2011中国 ...
- View的双击动作
有时在android中需要为某一控件设置双击监听,实现也挺简单,自己动手吧.编码永远不是问题,思路才是最重要. public class DoubleClickDemo extends Activit ...
- datable
$("#table_d").append("<table id='dmglTable' class='table table-striped table-hover ...
- 洛谷 P3804 【模板】后缀自动机 统计单词出现次数
后缀自动机模板题. 关键时求解每个节点的 $right$ 大小. 由于后缀自动机在构建时会保证点和点的 $right$ 只可能没有交集,或者一个是另一个的真子集,我们可以不重复的对 $right$ 进 ...