Nine degrees OJ topic 1029: Spell Dictionary

Source: Internet
Author: User
Tags strcmp silver light

A. Title Description:
One of Harry Potter's compulsory courses at the school of Witchcraft and Wizardry is learning spells. It is said that there are 100000 different enchantments in the Wizarding world, and it is difficult for Harry to remember it all, but in order to fight the enemy, he must be able to invoke any desired spell in a critical moment, so he needs your help.

Give you a spell dictionary. When Harry hears a spell, your program must tell him the function of the spell, and when Harry needs a function but does not know what spell to use, your program will find the appropriate spell for him. If the spell he wants is not in the dictionary, the output is "what?"

Input:
First, list no more than 100,000 different spell entries in the dictionary, each in the following format:

[Magic Spell] corresponding function

where "enchantments" and "corresponding functions" are strings that do not exceed 20 and 80 in length, the string guarantees that the characters "[" and "]" are not included, and that there is only one space between the "]" and the subsequent strings. The last line of the dictionary ends with "@END @", which does not belong to the entry in the dictionary.
The line after the dictionary contains a positive integer n (<=1000) followed by n test cases. Each test case takes on one line, or "[enchantments]", or "corresponding function".
Output:
The output of each test case is one line, the output enchantment corresponds to the function, or the function corresponding to the enchantments. If the spell is not in the dictionary, 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?


Two. Topic analysis

The topic is not difficult, is to store and find, this thought needs two points, will come to a tle, but nine degrees did not, that simple to do, however, I do not know why WA, has been changed to vomit, may be some details of the format did not notice, but now did not think how to change, temporarily paste the WA bar later changes.

Three. Code

#include <stdio.h> #include <stdlib.h> #define MAX 100000 typedef struct DICT {char mirotic[25];
Char function[85];
}directory;
Directory D[max];
int num;
    int main () {int i,j,k,n,re;

    Char ch,str[85];
    Freopen ("1029.txt", "R", stdin);

    num=0; while (1) {scanf ("%s", D[num].
        Mirotic); if (strcmp (d[num).

        Mirotic, "@END @") ==0) break; if (D[num].

        mirotic[0]== ' @ ') break;
        scanf ("%c", &ch);
        Gets (d[num].function);
    num++;
    } scanf ("%d", &n);
    GetChar ();
        for (i=0;i<n;i++) {gets (str); for (j=0;j<num;j++) {if (strcmp (Str,d[j]). Mirotic) ==0| |
        strcmp (str,d[j].function) ==0) break;
        } if (J==num) printf ("what?\n");
            else {if (str[0]== ' [') printf ("%s\n", d[j].function); else {for (k=1;d[j].
 Mirotic[k]!= '] '; k++)                   printf ("%c", D[j].
                Mirotic[k]);
            printf ("\ n");
}}} return 0;
 }




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.