HDOJ 1075 What Are You Talking About
2017-04-04 22:32
309 查看
[align=left][/align] |
What Are You Talking About[b]Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K (Java/Others)Total Submission(s): 22065 Accepted Submission(s): 7356 [/b] Problem DescriptionIgnatius 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 Ignatiuswant to translate the history book into English. Can you help him? [align=left] [/align] [align=left] [/align] InputThe 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", thisstring 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. [align=left] [/align] [align=left] [/align] Output[align=left]In this problem, you have to output the translation of the history book.[/align] [align=left] [/align] [align=left] [/align] Sample InputSTARTfrom fiwo hello difh mars riwosf earth fnnvk like fiiwj END START difh, i'm fiwo riwosf. i fiiwj fnnvk! END [align=left] [/align] [align=left] [/align] Sample Outputhello, i'm from mars.i like earth! Hint Huge input, scanf is recommended. |
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define f(i,a,b) for(int i=(a);i<=(b);++i)
const int maxn = 26;
const int mod = 1e9+7;
const int INF = 1e9;
#define ll long long
#define rush() int T;scanf("%d",&T);while(T--)
struct Trie
{
int flag;
char str[15];
Trie *next[maxn];
Trie()
{
flag=0;
memset(str,0,sizeof(str));
for(int i=0; i<maxn; i++)
next[i]=NULL;
}
};
Trie *root,*p;
void createTrie(char *w1,char *w2)
{
p=root;
for(int i=0; w1[i]!='\0'; i++)
{
int t=w1[i]-'a';
if(p->next[t]==NULL)
p->next[t]=new Trie;
p=p->next[t];
}
p->flag=1;
strcpy(p->str,w2);
}
void findTrie(char *w)
{
p=root;
for(int i=0; w[i]!='\0'; i++)
{
int id=w[i]-'a';
if(p->next[id]!=NULL)
p=p->next[id];
else
{
printf("%s",w);
return;
}
}
if(p->flag==1)
printf("%s",p->str);
else
printf("%s",w);
}
int main()
{
char a[15],b[15],t[15],str[3005];
root=new Trie();
scanf("%s",a);
while(scanf("%s",a),strcmp(a,"END"))
{
scanf("%s",b);
createTrie(b,a);
}
scanf("%s",a);
getchar();
while(gets(str),strcmp(str,"END"))
{
for(int i=0,k=0; str[i]!='\0'; i++)
{
if(islower(str[i]))
t[k++]=str[i];
else
{
t[k]='\0';
findTrie(t);
memset(t,0,sizeof(t));
k=0;
printf("%c",str[i]);
}
}
printf("\n");
}
return 0;
}
相关文章推荐
- 【HDOJ】1075 What Are You Talking About
- Hdoj 1075 What Are You Talking About 【MAP】
- HDOJ 1075 What are you talking about ? 字典树
- hdoj--1075 What Are You Talking About(Trie or map)
- HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
- [HDOJ]problem_1075【What Are You Talking About】
- hdu/hdoj 1075 What Are You Talking About
- HDOJ/HDU 1075 What Are You Talking About(字符串查找翻译~Map)
- HDOJ 1075 What Are You Talking About(字典树)
- HDOJ 1075 What are you talking about (map + 字符串 )
- HDOJ 1075 What Are You Talking About(trie树入门)
- HDU/HDOJ 1075 What Are You Talking About(字典树|STL map)
- HDOJ.1075 What Are You Talking About(map)
- HDOJ 1075 -- What Are You Talking About Trie( STL )
- HDOJ 1075 What Are You Talking About
- ACM--火星文--HDOJ 1075--What Are You Talking About--map
- hdoj1075 What Are You Talking About
- hdoj 1075 What Are You Talking About 【STL map+string】
- hdoj1075 What Are You Talking About(STL map处理字符串)
- [HDOJ1075]What Are You Talking About