hdoj1075 What Are You Talking About
What Are You Talking About
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)
Total Submission(s): 10226 Accepted Submission(s): 3238
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.
START
#pragma warning(disable:4786)
#include<iostream>
#include<string>
#include<cstring>
#include<map>
using namespace std;
map<string,string>m;
map< string , string >::iterator it;
void fuu(char a[])
{
it = m.find(a) ; if( it != m.end() )
cout<<it->second;
else cout<<a;
}
void fun(char mm[])
{
char s[];
int i,nn=;
int x=strlen(mm);
for(i=; i<x; i++)
{
if(mm[i]!=' ' && mm[i]>='a' && mm[i]<='z')//把所有字符串中的单词转化成单个的单词,然后再map容器中寻找
{
s[nn++]=mm[i];
if(i==x-)
{
s[nn]='\0';
fuu(s);
cout<<mm[x-];
break;
}
}
else if(mm[i]==' ' || (mm[i]<'a' || mm[i]>'z'))
{
s[nn]='\0';
if(nn>)
fuu(s);
nn=;
cout<<mm[i];
}
}
return ;
}
int main()
{
// freopen("Out.txt","w",stdout);
int len;
char a[],b[],mm[],ch[];
cin>>ch;
while()
{
cin>>a>>b;
len=strlen(a);
if(len== && a[]=='E' && a[]=='N' && a[]=='D')
break;
m[b]=a;
}
int i=;
while()
{
gets(mm);
len=strlen(mm);
if(len== && mm[]=='E' && mm[]=='N' && mm[]=='D')
{
break;
}
fun(mm);
if(i>)
cout<<endl;//格式错了调了一个小时啊,最后才在这加了一个
i++;
}
return ;
}
hdoj1075 What Are You Talking About的更多相关文章
- HDOJ1075字典翻译(map应用)
#include<iostream> #include<cstdio> #include<map> #include<string> #include& ...
随机推荐
- redis 安装 命令
安装: http://redis.io/download 在线操作命令:http://try.redis.io/ 命令查询:https://redis.readthedocs.org/en/lates ...
- html页面禁止选择复制剪切
在body加入 onselectstart="return false" oncopy="return false;" oncut="return f ...
- org.dom4j.DocumentException:对实体 "virtual_card_id" 的引用必须以 ';' 分隔符结尾
Error on line 1 of document : 对实体 "virtual_card_id" 的引用必须以 ';' 分隔符结尾. CreateTime--2018年 ...
- Xiuno BBS 3.0 轻论坛程序正式版发布。
github:git clone -b v3.0 https://git.oschina.net/xiuno/xiunobbs 安装包:http://bbs.xiuno.com/down/xiuno_ ...
- MongoDB: 聚集管道
在MongoDB2.2新出现的. 聚集管道式基于数据处理管道概念建模的数据聚集框架.文档进入一个多阶段能将该文档转化为聚集结果的管道. 聚集管道提供了map-reduce方法了替代物,并在非常多聚集任 ...
- Android API之android.provider.ContactsContract.Data
android.provider.ContactsContract.Data Constants for the data table, which contains data points tied ...
- AjaxControlToolkit的使用
摘自:http://www.cnblogs.com/zm235/archive/2008/05/09/1189558.html 暂时的做法: 把AjaxControlToolkit.dll复制到项目的 ...
- MySQL JOIN操作报错问题小解
1 问题描述 在调用一个MySQL存储过程的时候,有时候会出现下面的错误: Illigal mix of collations(gbk\_chinese\_ci, IMPLICIT) and (lat ...
- python函数中把列表(list)当参数时的"入坑"与"出坑"
在Python函数中,传递的参数如果默认有一个为 列表(list),那么就要注意了,此处有坑!! 入坑 def f(x,li=[]): for i in range(x): li.append(i*i ...
- 使用git 将自己的本地文件git到github上面的完整过程
1. 首先在github网站上新建一个仓库,复制仓库地址(HTTP形式或者SSH形式,后者利用SSH,在最后一步push 的时候可以不用输入用户名和密码). 2. 在本地某个你想要的(文件夹)目录 ...