列表

详情


NC24431. Clarifications

描述

The university programming contest of HIT@WH is going to start!

As the main problem setter, Ramen is going to reply to the requests for clarification during the contest. 

The level of the contestants is varied so that they will ask different questions. Some questions are foolish, the most stupid one among them is: Why I got WA on problem X?. Some are critical that may indicate that there is something went wrong, and juries need to investigate.

To make different responses for each request is unnecessary and boring, so Ramen has his own rules to answer the contestant. Here are the rules of how he makes a response:

- If the request is a statement, he will answer No Response.
- If the request is a stupid question, he will answer 42.
- If the question is not a stupid question and the question has been asked less or equal than five times, he will answer Read the problem statement carefully.
- If the question is not a stupid question and the question has been asked more than five times, he will answer Juries are investigating. Thanks.

A statement ends with a period(.) while a question ends with a question mark(?).

The contest is running, but Ramen has some urgent work to do, so he is absent. You know Ramen's rules, can you help him for a while?

输入描述

The input contains multiple lines.

The first line contains two integers n, q(1 <= n <= 10000, 1 <= q <= 100), indicates the number of requests and the number of stupid questions.

Each of the next q lines contains a distinct stupid question.

Then each of the next n lines contains a request for clarification.

It's guaranteed that the all given strings will only contain Latin letters and spaces, and each line ends with a period or a question mark. The length of each of them will not exceed 100.

输出描述

Output exactly n lines. The i-th line represents the answer to the i-th request of clarifications.

示例1

输入:

10 2
Why I got WA on problem A?
How to solve problem C?
The problems are really good.
Why I got WA on problem A?
Why I got CE?
Why I got CE?
How to solve problem C?
Why I got CE?
Why I got CE?
Why I got CE?
The constraint of E is correct?
Why I got CE?

输出:

No Response.
42.
Read the problem statement carefully.
Read the problem statement carefully.
42.
Read the problem statement carefully.
Read the problem statement carefully.
Read the problem statement carefully.
Read the problem statement carefully.
Juries are investigating. Thanks.

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

Python(2.7.3) 解法, 执行用时: 34ms, 内存消耗: 4064K, 提交时间: 2019-04-14 13:00:16

l = raw_input().strip().split()
n = int(l[0])
q = int(l[1])

stp = [raw_input().strip() for i in range(q)]

count = {}

for i in range(n):
    line = raw_input().strip()
    if line.endswith("."):
        print "No Response."
    elif line in stp:
        print "42."
    else:
        if line not in count:
            print "Read the problem statement carefully."
            count[line] = 1
        else:
            if count[line] < 5:
                print "Read the problem statement carefully."
                count[line] += 1
            else:
                print "Juries are investigating. Thanks."

Go(1.9.1) 解法, 执行用时: 44ms, 内存消耗: 2656K, 提交时间: 2019-04-14 21:32:24

package main
import (
	"bufio"
	"fmt"
	"os"
	"strings"
)
func main(){
    var (
		n int
		m int
	)
	fmt.Scanf("%d %d",&n,&m)
	s1 := make(map[string] int)
	input := bufio.NewScanner(os.Stdin)
	for i:=0;i<m;i++{
		input.Scan()
		s1[input.Text()]=-1
	}
	for j := 0; j < n; j++ {
		input.Scan()
		if strings.HasSuffix(input.Text(),".") {
			fmt.Println("No Response.")
		}else if s1[input.Text()]==-1{
			fmt.Println("42.")
		}else if s1[input.Text()]<5 {
			s1[input.Text()]++
			fmt.Println("Read the problem statement carefully.")
		}else {
			fmt.Println("Juries are investigating. Thanks.")
		}
	}
}

C++14(g++5.4) 解法, 执行用时: 37ms, 内存消耗: 1636K, 提交时间: 2019-04-14 12:40:29

#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
set<string>s;
int main()
{
	int n,m;
	cin>>n>>m;
	getchar();
	while(m--)
	{
		string ss;
		getline(cin,ss);
		s.insert(ss);
	}
	while(n--)
	{
		string ss;
		getline(cin,ss);
		if(s.count(ss))
		{
			cout<<"42."<<endl;
			continue;
		}		
		int l=ss.size();
		if(ss[l-1]=='.')
		{
			cout<<"No Response."<<endl;
		}
		else
		{
//			cout<<mp[ss]<<"?????"<<endl;
			if(mp[ss]>=5)
			cout<<"Juries are investigating. Thanks."<<endl;
			else cout<<"Read the problem statement carefully."<<endl;
		}
		mp[ss]++;
	}
}

C++11(clang++ 3.9) 解法, 执行用时: 69ms, 内存消耗: 2388K, 提交时间: 2019-04-18 14:05:29

#include <bits/stdc++.h>
using namespace std;
map<string,int>p;
map<string,int>v;
int main()
{
	int n,q;
	string str,str1;
	cin>>n>>q;
	getchar();
	while(q--)
	{
		getline(cin,str1);v[str1]=1;
	}
	while(n--)
	{
	    getline(cin,str); 
		if(str[str.size()-1]=='.') printf("No Response.\n");
		else if(v[str]) printf("42.\n");
		else{
			if(p[str]<5) printf("Read the problem statement carefully.\n");
			else printf("Juries are investigating. Thanks.\n");
		}
		++p[str];
	}
}

上一题