字典翻译问题

这一次比赛还是再简单题上面浪费了很多时间 唉 我太菜了

还是来说一下这字典翻译的问题吧

What Are You Talking About

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

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.

这个题目大致的意思就是以“START”和“END”作为间隔 分别给你一个字典(意思 单词)和需要你进行翻译的单词(长句)

先挂上由MAP和STRING的STL容器过的代码吧

#include

using namespace std;
const int maxn=550005;

char str[maxn][26],key[26];
char word[maxn];
string q;
mapfanyi;
map::iterator it;
int main()
{
    char st[6],ss[26];
    scanf("%s",st);
    int tot=1;
    while(scanf("%s",ss))
    {
        if(ss[0]=='E')
            break;
        strcpy(str[tot],ss);
        scanf("%s",key);
        fanyi.insert(pair(key,tot));
        tot++;
    }
    //for(it=fanyi.begin();it!=fanyi.end();it++)
        //cout<<first<<' 'second]<='a'&&word[i]<='z')
                q.push_back(word[i]);
            if(word[i]<'a'||i==len-1)
            {
                if(!q.empty())
                {
                    it=fanyi.find(q);
                    if(it!=fanyi.end())
                        cout<second];
                    else
                        cout<

还有一个我是用字典树做的,我找了很久 还是WA 希望路过的大佬们能帮我看看**=.=**

#include
#include
#define LL long long
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f

using namespace std;
const int maxn=550005;


struct node
{
    int jiu[26];
    char xin[26];
} trie[maxn];
struct Node
{
    int n1,n2;
};
int tot=0,number=0;
char fanyi[maxn],st[maxn];
char neww[maxn],oldw[maxn];
string q;
void iinsert(char oldw[])
{
    int i,j,rt=0;
    int len=strlen(oldw);
    for(i=0; i0)
        {
            while(1)
            {
                gets(fanyi);
                if(fanyi[0]=='E')
                {
                    flag=1;
                    break;
                }
                int len=strlen(fanyi);
                /*printf("len=%d\n",len);
                for(i=0;i='a'&&fanyi[i]<='z')
                        q.push_back(fanyi[i]);
                    if(fanyi[i]<'a'||i==len-1)
                    {
                        //cout<

你可能感兴趣的:(随笔)