## Hotline

View as PDF

Points: 50
Time limit: 1.0s
Memory limit: 64M

Problem type

Due to the incorrect reference solution that was provided, additional test cases have been provided. Data are provided by Ninjaclasher.

Every customer sometimes needs help with new and unusual products. Therefore, hotline service is very important for every company. We need a single phone number where the customer can always find a friendly voice ready to help with anything. On the other hand, many people are needed to serve as hotline operators, and human resources are always very expensive. Moreover, it is not easy to pretend "friendly voice" at 4am and explain to a drunken man that you are really unable to give him the number to House of Parliament. It was also found that some of the questions repeat very often and it is very annoying to answer them again and again.

ACM is a modern company, wanting to solve its hotline problem. They want to decrease the number of human operators by creating a complex software system that would be able to answer most common questions. The customer's voice is analysed by a special Voice Recognition Module (VRM) and converted to a plain text. The text is then taken by an Artificial Automatic Adaptive Answering Algorithm (AAAAA). The most common questions are recognised and answered automatically. The replies are then converted to a sound by Text-to-Speech Module (TTS).

You are to write the AAAAA module. Because your algorithm should be adaptive, it has no explicit knowledge base. But it must be able to listen to sentences in English and remember the mentioned facts. Whenever the question is asked about such a fact, the system has to answer it properly. The VRM and TTS modules are already implemented, so the input and output of AAAAA will be in the text form.

#### Input

There is a single positive integer on the first line of input. It stands for the number of dialogues to follow. Each dialogue consists of zero or more lines, each of them containing one sentence: either statement or question. The statement ends with a dot character (.), the question ends with a question mark (?). No statement will appear more than once, however the questions can be repeated. There is one extra line after each dialogue. That line ends with an exclamation mark (!).

Sentences can contain words, spaces and punctuation characters (such as commas, colons, semicolons etc.). All words contain only letters of English alphabet and are case-sensitive. That means the same word is always written the same way, usually in lowercase. Acronyms, names and some other words can begin with capital letters. For simplicity, all sentences begin with a lowercase letter. Only if the first word should be written with a capital, the sentence begins with a capital letter. There are no unneeded spaces between words. No line will have more than 100 characters. There will be at most 100 statements per each test case.

Statements

Each statement has one of the following two forms (~ denotes a space):

subject ~ predicate[s] [ ~ object] .

subject ~ don't|doesn't ~ predicate [ ~ object].

The square brackets mark an optional part, the vertical line two possible variants. Subject is a single word, noun or pronoun in singular. Predicate is a verb (single word) denoting some activity. Object can be any text. Object does not contain any dots. Any pair "verb + object" determines unique activity. The same verb with different objects makes different independent activities, i.e. the different and independent meaning of the sentence. Sentence without any object can be considered as sentence with an empty object. The verb without an object has different and independent meaning than the same verb with any non-empty object.

The first variant of sentence denotes a positive statement. The word "predicate[s]" means verb that matches the subject of the sentence. If the subject is "I" or "you", the verb has the same form as the infinitive. With any other subject, the letter "s" is appended on the end of the verb. Assume there are no irregular verbs.

The second variant is a negative statement. Verb "don't" or "doesn't" must also match the subject. The form "don't" is used with either "I" or "you", "doesn't" is used in any other case.

A special generic subject "everybody" can be used. It means the activity holds for any subject. Other special subject is "nobody". Such sentence also holds for any subject, but its meaning is negative. Both of these generic subjects can be used with the first variant only (without "doesn't"). The sentence "nobody likes something" is exactly equal to "everybody doesn't like something", except the latter form will never occur in the input.

Questions

Each question has one of the following three forms:

1. do|does ~ subject ~ predicate [ ~ object] ?
2. who ~ predicates [ ~ object] ?
3. what ~ do|does ~ subject ~ do ?

The word "do|does" always matches the subject ("do I?", "do you?", "does any other subject?"). In the second type of question, predicate always matches the word "who", i.e. the "s" is always appended. Generic subjects cannot be used in questions.

#### Output

For each dialogue, your program must output the line Dialogue #:, where is the sequence number of dialogue, starting with 1. Then print exactly three lines for every question: the first line repeats the question, the second line contains the answer, and the third line is empty. Print nothing for statements. After each dialogue, print the same line with an exclamation mark that was in the input. Then print one extra empty line. Empty line contains a new-line character only.

The answer must be properly formated to be accepted by a TTS module. Only the statements appearing in the input before the answer are used for the corresponding reply. If there is any contradiction among statements, the reply is always I am abroad.. If the question and statements consider the special subject "you", it must be replaced with "I" in the answer. If the question considers special subject "I", it must be replaced with "you" in the answer. The verb must always match the subject of the sentence. The exact form of the correct answer depends on the type of question.

1. does subject predicate [object] ?

If there is any positive statement about the mentioned subject (or generic subject "everybody"), predicate and object, the answer is: yes, ~ subject ~ predicate[s] [ ~ object] .

If there is any negative statement about the mentioned subject (or generic subject "nobody"), predicate and object, the answer is: no, ~ subject ~ don't|doesn't ~ predicate [ ~ object] .

Otherwise, the answer is: maybe.

Subject in the answer is always the same subject as the subject of the question.

2. who predicates [object] ?

If there is a positive statement considering any subject, the specified predicate and object, the answer is: subject ~ predicate[s] [ ~ object] .

If two or more subjects match the activity, replace the subject in the answer with enumeration of all such subjects, in the same order as the corresponding statements have appeared in the input. Subjects are separated with comma and space, last two subjects are separated with the word "and". If "everybody" belongs to the group of enumerated subjects, do not enumerate subjects, and print "everybody" only. If the enumeration contains at least two subjects, the predicate matches the plural subject (i.e. verb is without trailing "s"), otherwise it matches the only subject. subject1 , ~ subject2 ~ and ~ subject3 ~ predicate [ ~ object] .

If there is a negative statement considering the generic subject "nobody", the specified predicate and object, the answer is: nobody ~ predicates [ ~ object] .

Otherwise, the answer is: I don't know.

3. what does subject do ?

If there are one or more sentences (both positive and negative) considering the specified subject (or a generic subject "everybody" or "nobody"), all verbs and objects from such sentences must be included in a reply in the same order as the corresponding sentences have appeared in the input. No verb-object pair can be included more than once (the eventual second appearance must be skipped). The verb-object pairs are separated by a comma followed by a space, the last verb is separated by a comma and the word "and". Please note the comma is printed here although there was no comma when separating the subjects in the previous type of answer (see above). The negative answers have the same form as the statements, that means the verb "don't" or "doesn't" is used:

subject [ ~ don't|doesn't] ~ predicate1[s] [ ~ object1] ,

[ ~ don't|doesn't] ~ predicate2[s] [ ~ object2] ,

~ and [ ~ don't|doesn't] ~ predicate3[s] [ ~ object3] .

subject [ ~ don't|doesn't] ~ predicate1[s] [ ~ object1] ,

~ and [ ~ don't|doesn't] ~ predicate2[s] [ ~ object2] .

subject [ ~ don't|doesn't] ~ predicate[s] [ ~ object] .

Otherwise, the answer is: I don't know.

#### Sample Input

1
I like hotdogs.
nobody likes to work.
everybody smiles.
what do I do?
who smiles?
what do you do?
does Joe smile?
do I like to work?
everybody hurts sometimes.
who walks there?
Michal walks there.
who walks there?
what does Michal do?
do you understand?
nobody walks there.
do you understand now?
bye!

#### Sample Output

Dialogue #1:
what do I do?
you like hotdogs, don't like to work, and smile.

who smiles?
everybody smiles.

what do you do?
I don't like to work, and smile.

does Joe smile?
yes, Joe smiles.

do I like to work?
no, you don't like to work.

who walks there?
I don't know.

who walks there?
Michal walks there.

what does Michal do?
Michal doesn't like to work, smiles, hurts sometimes, and walks there.

do you understand?
maybe.

do you understand now?

bye!

• geese  commented on March 13, 2019, 12:08 a.m.

Has the original reference solution been corrected?

• Jeffmagma  commented on March 2, 2019, 6:52 p.m. edit 2

subject1 , ~ subject2 ~ and ~ subject3 predicate [~ object].

is this missing a ~ between subject3 and predicate?

Sentences can contain words, spaces and punctuation characters (such as commas, colons, semicolons etc.)

also, when are semicolons and colons used?

• wleung_bvg  commented on March 2, 2019, 10:50 p.m.

Yes, there should be a space. The semicolons and colons may appear in the sentence anywhere, but without breaking any of the rules. They should just be treated the same way as alphanumeric characters.

• benito255  commented on Feb. 25, 2019, 12:22 p.m.

I don't suppose someone can check to see why I'm getting a WA? It seems to give the correct output for the test data and I've thrown quite a few variations in for testing, but this is a hard one without any feedback :)

Sorry in advance for the horrible code - still learning python!

• geese  commented on Feb. 25, 2019, 11:08 p.m.

Less horrible than my code tbh

• wleung_bvg  commented on Feb. 25, 2019, 2:05 p.m. edit 2

When answering the who question, you do not switch I to you and vice versa.

• snowdozer  commented on March 8, 2019, 3:16 p.m. edited

this comment hung me up for a while because I thought it referred to the generic subject "you" (everyone shouldn't swap I and you) rather than the direct subject "you" (benito255 doesn't swap I and you). seems kind of fitting considering the question lol

• benito255  commented on Feb. 25, 2019, 7:30 p.m.

Thanks so much! That was one of about 10 problems I eventually found with my code. Took some more thorough testing to get there in the end...

• p1geon  commented on Feb. 24, 2019, 11:25 p.m.

will "nobody" be used as a subject in a question

• geese  commented on Feb. 25, 2019, 10:41 a.m.

Generic subjects cannot be used in questions.

• Jeffmagma  commented on Feb. 24, 2019, 5:27 p.m.

wait is it a contradiction if they say everybody smiles. then nobody smiles.? or does the nobody smiles. overwrite the everybody smiles.?

• d  commented on Feb. 24, 2019, 6:22 p.m.

Yes.

No, all statements are true at the same time.

• Jeffmagma  commented on March 2, 2019, 4:18 p.m.

So if they say Joe eats. then Joe doesn't eat. that's a contradiction too?

• Zeyu  commented on Feb. 24, 2019, 7:15 a.m. edit 2

If the subject is "nobody" or "everybody", do we check all the subjects or only their respective subject? Also, do we still have to print an extra empty line for the last dialogue?

EDIT: Okay I somehow passed. Here are the answers to the questions I had above:

• Only check their respective subject. If it's nobody or everybody it doesn't mean you check all the other people.
• Always print an extra line in the end. Even if the example doesn't show the last line.
• qiuxinrong27  commented on Feb. 23, 2019, 11:56 p.m.

My "Hello, World" program is slower than the AC solution :/

• Jeffmagma  commented on Feb. 23, 2019, 5:36 p.m. edited

is it possible for one predicate to have multiple objects in different statements? for example Joe likes cheese. then Joe likes tacos.

also, what does bye! mean? it isn't stated anywhere that it indicates the end of a dialogue

• Zeyu  commented on Feb. 24, 2019, 8:19 a.m.

Yes, The same verb with different objects makes different independent activities. Also, the exclamatory mark of bye! indicates the dialogue's end.

• Jeffmagma  commented on Feb. 24, 2019, 1:21 p.m.

can you give some hints on what i'm doing wrong? do i have to use a better data structure?

• Zeyu  commented on Feb. 24, 2019, 1:35 p.m.

The issue with your TLE isn't what you think it is, reread how every dialogue ends in the input section :)

• Jeffmagma  commented on Feb. 24, 2019, 4:59 p.m.

ohhh ok, i'm dumb thanks