eolymp
bolt
Try our new interface for solving problems
Məsələlər

Universal Question Answering System

Universal Question Answering System

Every student needs help from getting new knowledge by asking questions. Surveys are suggesting that some similar questions are repeated frequently. So it will be nice to develop an automatic question-answering system to answer these questions. Your algorithm should not have any prior knowledge, but it must be able to read sentences and remember the mentioned facts. Whenever the question is asked about such a fact, the system has to answer it properly. \InputFile The input consists of many dialogues. There is a single positive integer \textbf{T} on the first line of input. (\textbf{T} ≤ \textbf{500}, but note that \textbf{95}\% of them are relatively small) It denotes the number of following dialogues. Each dialogue includes one or more lines. Each line contains one sentence: either a statement or a question. Statements end with a dot character (\textbf{.}) while questions end with a question mark (\textbf{?}). There is one extra line after each dialogue. That line ends with an exclamation mark (\textbf{!}). The definitions of the statements and questions will be discussed later. Sentences can contain words, spaces and punctuation characters. All words contain only Latin letters and are case-sensitive. Unlike the normal English writing rules, the first letter of a sentence should keep lowercase unless the first word itself should begin with a capital letter. There are no extra spaces between words. No word will have more than \textbf{10} characters. There will be at most \textbf{1000} lines per dialogue. \textbf{Statements} Each statement has one of the following forms: \textit{oun_phrase are noun_phrase.noun_phrase can verb_phrase.everything which can verb_phrase can verb_phrase.everything which can verb_phrase are noun_phrase.} noun_phrase and verb_phrase are both single word. The meanings of the four forms are: \textbf{A} are \textbf{B}: If \textbf{X} is \textbf{A}, then \textbf{X} is \textbf{B}.\textbf{A} can \textbf{B}: If \textbf{X} is \textbf{A}, then \textbf{X} has the ability to \textbf{B}.everything which can \textbf{A} can \textbf{B}: If \textbf{X} has the ability to \textbf{A}, \textbf{X} has the ability to \textbf{B}.everything which can \textbf{A} are \textbf{B}: If \textbf{X} has the ability to \textbf{A}, \textbf{X} is \textbf{B}. \textbf{Questions} Each question has one of the following forms: \textit{are noun_phrase noun_phrase?can noun_phrase verb_phrase?can everything which can verb_phrase verb_phrase?are everything which can verb_phrase noun_phrase?} They are the question form of the statements. In each test case, the number of different noun phrases will not exceed \textbf{ 100}; the number of different verb phrases will not exceed \textbf{100}. \OutputFile For each test case, output two lines. The first line describes the test case number counting from \textbf{1}, while the second line contains the same number of characters as the number of questions in this test case. Each character is either '\textbf{Y}' (denoting you can get that fact logically) or '\textbf{M}' (otherwise), without quotes.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
1
flies can fly.
flies are insects.
everything which can fly are animals.
are everything which can fly insects?
are flies animals?
can flies eat?
everything which can fly can eat.
can flies eat?
Bye!
Çıxış verilənləri #1
Case #1:
MYMY
Mənbə The 36th ACM-ICPC Asia Shanghai Regional Contest - hosted by Fudan University