What are you talking about(HDU1075)

来源:互联网 发布:ubuntu root密码忘记 编辑:程序博客网 时间:2024/05/21 17:08

体会:好久没有做这样的题,感觉写的,,注意的细节比较多。出了各种问题,好不容易啊,

#include<iostream>#include<stdlib.h>#include<math.h>#include<stdio.h>#include<algorithm>#include<queue>#include<string.h>#include<stack>#include<math.h>#include<stdlib.h>#include<list>#include<vector>using namespace std;#define N 500000#define M 11#define L 3001struct my{    char a[M];    char b[M];}dic[N];int n;bool f;bool cmp(my A,my B){    if (strcmp(A.b,B.b)>0)        return false;    else        return true;}void find(char cur[],int front,int end){    int i,j,k;    int mid=(front+end)/2;    //cout<<cur<<' '<<dic[mid].b<<' '<<front<<' '<<end<<endl;    if (strcmp(cur,dic[mid].b)==0)    {        f=false;        printf("%s",dic[mid].a);        return ;    }    if (strcmp(cur,dic[mid].b)>0&&end>mid)        find(cur,mid+1,end);    else if (mid>front)        find(cur,front,mid-1);}int  main(){    int i,j,k;    freopen("fuck.txt","r",stdin);    char go[L];    int l;    scanf("%s",go);    k=0;    while (true)    {        scanf("%s",go);        if (strcmp(go,"END")==0)            break;        strcpy(dic[k].a,go);        scanf("%s",go);        strcpy(dic[k++].b,go);    }    n=k;    sort(dic,dic+n,cmp);    //for (i=0;i<n;i++)    //    cout<<dic[i].a<<' '<<dic[i].b<<endl;    scanf("%s",go);    char c=getchar();    while (true)    {        gets(go);        //cout<<go<<endl;        if (strcmp(go,"END")==0)            break;        l=strlen(go);        j=0;        i=0;        char cur[L];        while (i<l)        {            if (go[i]>='a'&&go[i]<='z')            {                cur[j++]=go[i];            }            else            {                if (j)                {                    cur[j]='\0';                    //cout<<endl<<cur<<endl;                    f=true;                    find(cur,0,n-1);                    if (f)                        printf("%s",cur);                }                j=0;                printf("%c",go[i]);            }            i++;        }        if (j)        {            cur[j]='\0';            f=true;            find(cur,0,n-1);            if (f)                printf("%s",cur);            j=0;        }        printf("\n");    }}




What Are You Talking About

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


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
STARTfrom fiwohello difhmars riwosfearth fnnvklike fiiwjENDSTARTdifh, i'm fiwo riwosf.i fiiwj fnnvk!END
 

Sample Output
hello, i'm from mars.i like earth!
Hint
Huge input, scanf is recommended.
 

Author


原创粉丝点击