题意:

给你一个字典 一个英文单词对应一个火星单词 给你一段火星文翻译成英文 字典上的没有的不翻译

分析:

没有给数据规模 字典树用链表

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int maxn = 1e5+;
const int mod = ;
struct trie{
string tran;
trie *next[];
};
trie *root;
void init(){
root=new trie;
root->tran[]='*';
for(int i=;i<;++i)
root->next[i]=NULL;
}
void build(string eng,string mar){
int l=mar.length();
trie *p=root;
for(int i=;i<l;++i){
int tmp=mar[i]-'a';
if(p->next[tmp]==NULL){
p->next[tmp]=new trie;
p=p->next[tmp];
p->tran[]='*';
for(int j=;j<;++j)
p->next[j]=NULL;
}
else{
p=p->next[tmp];
}
}
p->tran=eng;//存对应的英文单词
}
void dele(trie *root){
for(int i=;i<;++i){
if(root->next[i]!=NULL)
dele(root->next[i]);
}
delete(root);
}
string query(string mar){
int l=mar.length();
trie *p=root;
for(int i=;i<l;++i){
int tmp=mar[i]-'a';
if(p->next[tmp]==NULL)return mar;//没查到
p=p->next[tmp];
}
if(p->tran[]=='*')return mar;
return p->tran;
}
int main()
{
init();
string s1,s2;
while(cin>>s1){
if(s1=="START")continue;
if(s1=="END")break;
cin>>s2;
build(s1,s2);
}
getchar();
while(getline(cin,s1)){
if(s1=="START")continue;
if(s1=="END")break;
string str1="",str2="";
for(int i=;i<s1.length();++i){
if(s1[i]>='a'&&s1[i]<='z'){
str1+=s1[i];
}
else{
str2+=query(str1);
str1="";
str2+=s1[i];
}
}
cout<<str2<<endl;
}
// dele(root);
return ;
}

最新文章

  1. C和指针 第十六章 标准函数库
  2. 如何查看Linux的系统是64位的还是32位的
  3. HXOI 2014 PSet 4 Day 1 一模04日1 题解
  4. poj2482 Stars in Your Window
  5. ViewPager使用笔记
  6. Android Dalvik虚拟机初识(转)
  7. jmp指令
  8. Eclipse配色插件
  9. “error LNK1169: 找到一个或多个多重定义的符号”的解决方法(转载)
  10. 你的第一个AngularJS应用--教程二:基架、建立和測试的工具
  11. STL迭代器与部分算法学习笔记
  12. 11.C++-临时对象分析
  13. 【一天一道LeetCode】#130. Surrounded Regions
  14. Leetcode_154_Find Minimum in Rotated Sorted Array
  15. ELK从5.6.3升级到6.3.0总结
  16. [C#]做服务使用Process启动外部程序没窗体
  17. jquery 图片文件转base64 显示
  18. js json日期格式转换日期方法
  19. 记录下一个自己不常用的关键字-yield
  20. 2018.11.23 Cypress BLE module test

热门文章

  1. 【BZOJ2428】[HAOI2006]均分数据
  2. hive-site.xml 参数设置
  3. Contest2037 - CSU Monthly 2013 Oct (problem D :CX and girls)
  4. Good Bye 2015B
  5. unity3d与eclipse协同工作环境
  6. BindingFlags说明
  7. Codeforces Round #240 (Div. 2)(A -- D)
  8. 深入剖析Classloader(二)--根类加载器,扩展类加载器与系统类加载器
  9. 用java运行Hadoop程序报错:org.apache.hadoop.fs.LocalFileSystem cannot be cast to org.apache.
  10. VLAN是什么