Codeforces April Fools Day Contest 2021-A. Is it rated - 2-题解

222 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

@TOC

Codeforces April Fools Day Contest 2021-A. Is it rated - 2

传送门 Time Limit: 1 seconds Memory Limit: 256 megabytes

Interaction

This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file.

In each query, you will be asked the question, written in one line. You have to answer it correctly, patiently and without any display of emotions. Your response is case-insensitive.

Please make sure to use the stream flushing operation after each response in order not to leave part of your output in some buffer.

Example

Input

Is it rated?
Is it rated?
Is it rated?

OutPut

NO
NO
NO

题目大意

测评机每次会询问你Is it rated?,你需要每次都回答NO


注意事项

这是一道交互题,在得到你的输出后,测评机才会输入下一个询问。 所以,要及时清空缓冲区。


清空缓冲区的方法

C语言

fflush(stdin);

Python

import sys
sys.stdout.flush()

为什么要清空缓冲区

程序中的print并不一定会及时打印,而有可能是先储存在缓冲区中,达到一定条件一次性共同输出。 这个可以用sleep来测试。比如python如果

import time
for i in range(5): 
   print('*', end='')
   time.sleep(2)

那么可能会看到过了10s,5个*同时出现了。

很多程序在输出换行时会清空缓冲区,比如C++中的cout << endl 但是如果怕的话,就加上一个fflush(stdin)等,强制清空缓冲区,多少东西都打印。


另外

如果做过去年(2020)愚人节的A题的话,这一题大眼一看就能得到答案了。


AC代码

#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define fi(i,l,r) for(int i=l;i<r;i++) 
#define cd(a) scanf("%d",&a)
typedef long long ll;

int main()
{
	string s;
    while(cin>>s)
    {
        puts("NO");
        //fflush(stdin);
        //这题不加也能过
    }
	return 0;
}

同步发文于我的CSDN,原创不易,转载请附上原文链接哦~
Tisfy:letmefly.blog.csdn.net/article/det…