时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld
题目描述
You don’t know anything about programming, but nonetheless you and your friend Bob joined the BAPC. Bob just submitted a solution to a problem, but sadly his submission was not accepted. You will help him fifigure out what mistake he made. In order to do so, he will explain what every part of the program should do according to him. He does not want you to interrupt him while he is explaining, but whenever he is unsure of
something, he will ask for confifirmation. Bob is actually a very good coder, so whenever he asks for confifirmation, he is simply right. You just need to react by nodding and saying “Quack!”. As long as you don’t interrupt him at the wrong time, and as long as you say “Quack!” at the right times, he will eventually fifind his mistake and he will shout “I quacked the code!”.
输入描述:
This is an interactive problem. Your submission will be run against an interactor, which reads the standard output of your submission and writes to the standard input of your submission. This interaction needs to follow a specifific protocol:
The interactor sends one line of text at a time, each line being one sentence of Bob’s monologue. You need to reply as follows:
• If the line ends with a question mark (“?”), your reply must be the string “Quack!”.
• If the line ends with a period (“.”), your reply must be the string “*Nod*”.
• If the line is exactly “I quacked the code!”, your submission should exit. Reading more input will result in a time limit exceeded and printing more output will result in a wrong answer.
Bob’s monologue will be no more than 100 sentences, with at most 100 characters in total. It is guaranteed that every sentence, except the last one, ends with a question mark (“?”) or a period (“.”).
Make sure you flflush the buffer after each write.
A testing tool is provided to help you develop your solution.
输出描述:
示例1
输入
复制
In the loop, I read a line of input.
The method std::getline(std::cin, line); reads until a newline, right?
Then I branch according to the last character of the line of input.
When the character is an exclamation mark, I terminate the program.
When it is a question mark, I need to print "Quack!" right?
In any other case, I simply print "*Nod*".
Wait, to flush the output stream I need to use std::endl instead of '\n' right?
I quacked the code!
输出
复制
*Nod*
Quack!
*Nod*
*Nod*
Quack!
*Nod*
Quack!
示例2
输入
复制
My program seems to always exit after reading one line.
Shouldn't it only halt when a line ends with an exclamation mark?
After reading a line, I check the last character using a switch.
When the character is a period, I print "*Nod*".
When the character is a question mark, I print "Quack!".
Wait, both get printed before the program exits?
I guess I forgot to add break; here and there...
I quacked the code!
输出
复制
*Nod*
Quack!
*Nod*
*Nod*
*Nod*
Quack!
*Nod*