hdu 魔咒詞典

           魔咒詞典

Time Limit : 8000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)

Total Submission(s) : 51   Accepted Submission(s) : 23

Problem Description

哈利波特在魔法學校的必修課之一就是學習魔咒。據說魔法世界有100000種不同的魔咒,哈利很難全部記住,但是爲了對抗強敵,他必須在危急時刻能夠調用任何一個需要的魔咒,所以他需要你的幫助。

給你一部魔咒詞典。當哈利聽到一個魔咒時,你的程序必須告訴他那個魔咒的功能;當哈利需要某個功能但不知道該用什麼魔咒時,你的程序要替他找到相應的魔咒。如果他要的魔咒不在詞典中,就輸出“what?”

Input

首先列出詞典中不超過100000條不同的魔咒詞條,每條格式爲: [魔咒] 對應功能 其中“魔咒”和“對應功能”分別爲長度不超過20和80的字符串,字符串中保證不包含字符“[”和“]”,且“]”和後面的字符串之間有且僅有一個空格。詞典最後一行以“@END@”結束,這一行不屬於詞典中的詞條。 詞典之後的一行包含正整數N(<=1000),隨後是N個測試用例。每個測試用例佔一行,或者給出“[魔咒]”,或者給出“對應功能”。

Output

每個測試用例的輸出佔一行,輸出魔咒對應的功能,或者功能對應的魔咒。如果魔咒不在詞典中,就輸出“what?”

Sample Input

[expelliarmus] the disarming charm

[rictusempra] send a jet of silver light to hit the enemy

[tarantallegra] control the movement of one's legs

[serpensortia] shoot a snake out of the end of one's wand

[lumos] light the wand

[obliviate] the memory charm

[expecto patronum] send a Patronus to the dementors

[accio] the summoning charm

@END@

4

[lumos]

the summoning charm

[arha]

take me to the sky

Sample Output

light the wand

accio

what?

what?

 

題意:給出一個串,比如[expelliarmus] the disarming charm,前面[expelliarmus]又是一個串,後面的the disarming charm算一個,查詢前或後任意一個,都能找到他的後或者前。

用倆個數組來存儲前後串,空格用gets()接收,for循環遍歷

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    string s1[100005];
    string s2[100005];
    int n=0;
    while(cin>>a)
    {
        char m[1000];
        string s;
        if(a=="@END@") break;
        gets(m);
        int L=strlen(m);
        for(int i=1; i<L; i++)
        {
            s=s+m[i];
        }
        s1[n]=a;
        s2[n]=s;
        n++;
    }
    int t;
    scanf("%d\n",&t);
    while(t--)
    {
        char m[1000];
        string s;
        gets(m);
        int L=strlen(m);
        for(int i=0; i<L; i++)
        {
            s=s+m[i];
        }
        if(m[0]=='[')
        {
            int p=-1;
            for(int i=0; i<n; i++)
            {
                if(s1[i]==s)
                {
                    p=i;
                    break;
                }
            }
            if(p!=-1)
                cout<<s2[p]<<endl;
            else
                printf("what?\n");
        }
        else
        {
            int p=-1;
            for(int i=0; i<n; i++)
            {
                if(s2[i]==s)
                {
                    p=i;
                    break;
                }
            }
            if(p!=-1)
            {
               for(int i=1; i<s1[p].length()-1; i++)
                    printf("%c",s1[p][i]);
                printf("\n");
            }
            else
            {
                printf("what?\n");
            }
        }
    }
    return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章