CF200D.Programming Language
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, default values).
Valery decided to examine template procedures in this language in more detail. The description of a template procedure consists of the procedure name and the list of its parameter types. The generic type T parameters can be used as parameters of template procedures.
A procedure call consists of a procedure name and a list of variable parameters. Let's call a procedure suitable for this call if the following conditions are fulfilled:
- its name equals to the name of the called procedure;
- the number of its parameters equals to the number of parameters of the procedure call;
- the types of variables in the procedure call match the corresponding types of its parameters. The variable type matches the type of a parameter if the parameter has a generic type T or the type of the variable and the parameter are the same.
You are given a description of some set of template procedures. You are also given a list of variables used in the program, as well as direct procedure calls that use the described variables. For each call you need to count the number of procedures that are suitable for this call.
最近,瓦列里接触到了一门全新的编程语言。这门语言最吸引他的地方在于其模板函数与模板过程。需要提醒的是,模板是编程语言中用于编写泛型算法的工具,它无需指定某些参数(例如:数据类型、缓冲区大小、默认值)。
瓦列里决定更深入地研究该语言中的模板过程。一个模板过程的定义由过程名及其参数类型的列表组成。泛型类型 T 可被用作模板过程的参数类型。
一个过程调用由过程名和变量参数的列表构成。若一个过程满足以下全部条件,则称其适用于该调用:
- 其名称与被调用的过程名称相同;
- 其参数个数与该过程调用的参数个数相等;
- 过程调用中各变量的类型与其对应参数的类型匹配。变量类型与参数类型匹配,当且仅当该参数的类型为泛型类型
T,或该变量的类型与该参数的类型完全相同。
现给出一组模板过程的定义。同时给出程序中使用的一组变量,以及使用这些变量所进行的一系列直接过程调用。对每一次调用,请统计出适用于该调用的模板过程的数量。
输入格式
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of template procedures. The next n lines contain the description of the procedures specified in the following format:
"void procedureName (type_1, type_2, ..., type_t)" (1 ≤ t ≤ 5), where void is the keyword, procedureName is the procedure name, type_i is the type of the next parameter. Types of language parameters can be "int", "string", "double", and the keyword "T", which denotes the generic type.
The next line contains a single integer m (1 ≤ m ≤ 1000) — the number of used variables. Next m lines specify the description of the variables in the following format:
"type variableName", where type is the type of variable that can take values "int", "string", "double", variableName — the name of the variable.
The next line contains a single integer k (1 ≤ k ≤ 1000) — the number of procedure calls. Next k lines specify the procedure calls in the following format:
"procedureName (var_1, var_2, ..., var_t)" (1 ≤ t ≤ 5), where procedureName is the name of the procedure, var_i is the name of a variable.
The lines describing the variables, template procedures and their calls may contain spaces at the beginning of the line and at the end of the line, before and after the brackets and commas. Spaces may be before and after keyword void. The length of each input line does not exceed 100 characters. The names of variables and procedures are non-empty strings of lowercase English letters and numbers with lengths of not more than 10 characters. Note that this is the only condition at the names. Only the specified variables are used in procedure calls. The names of the variables are distinct. No two procedures are the same. Two procedures are the same, if they have identical names and identical ordered sets of types of their parameters.
第一行包含一个整数 n(1≤n≤1000)—— 模板过程的数量。接下来的 n 行描述这些过程,格式如下:
void procedureName (type_1, type_2, ..., type_t)(其中 1≤t≤5),其中 void 是关键字,procedureName 是过程名,type_i 是第 i 个参数的类型。语言中参数的类型可以是 "int"、"string"、"double",以及关键字 "T"(表示泛型类型)。
接下来一行包含一个整数 m(1≤m≤1000)—— 已声明变量的数量。随后的 m 行描述这些变量,格式如下:
type variableName,其中 type 是变量类型,取值为 "int"、"string" 或 "double";variableName 是变量名。
接下来一行包含一个整数 k(1≤k≤1000)—— 过程调用的数量。随后的 k 行描述这些过程调用,格式如下:
procedureName (var_1, var_2, ..., var_t)(其中 1≤t≤5),其中 procedureName 是过程名,var_i 是某个变量的名称。
描述变量、模板过程及其调用的各行,可能在行首、行尾、括号及逗号前后包含空格;关键字 void 前后也可能有空格。每行输入长度不超过 100 个字符。变量名和过程名均为非空字符串,仅由小写英文字母和数字组成,长度至多为 10 个字符。注意:这是对名称的唯一限制。过程调用中仅使用已声明的变量。所有变量名互不相同。不存在两个完全相同的过程;当且仅当两个过程具有相同的名称和完全相同的(按顺序排列的)参数类型集合时,才认为它们相同。
输出格式
On each of k lines print a single number, where the i-th number stands for the number of suitable template procedures for the i-th call.
在接下来的 k 行中,每行输出一个整数;其中第 i 行的整数表示第 i 次调用所对应的合适模板函数的数量。
输入输出样例
输入#1
4 void f(int,T) void f(T, T) void foo123 ( int, double, string,string ) void p(T,double) 3 int a string s double x123 5 f(a, a) f(s,a ) foo (a,s,s) f ( s ,x123) proc(a)
输出#1
2 1 0 1 0
输入#2
6 void f(string,double,int) void f(int) void f ( T ) void procedure(int,double) void f (T, double,int) void f(string, T,T) 4 int a int x string t double val 5 f(t, a, a) f(t,val,a) f(val,a, val) solve300(val, val) f (x)
输出#2
1 3 0 0 2
输入解题思路,AI测评打分。不知道怎么写?