Programming Language

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.

Input
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.

Output
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.

Sample 1
Input :
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)
Output :
2
1
0
1
0
Sample 2
Input:
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)
Output:
1
3
0
0
2
上文各位自行翻译吧,直接放代码。

#n为模板数量,m为变量数,k为调用数量。
#1
n = input()
template = []
function_name = []
for i in range(0,int(n)):
    str0 = input()
    template.append(str0)
    template[i]=template[i].replace("void"," ")
    template[i]=template[i].replace(" ","")
    function_name.append(template[i][0:template[i].find("(")])
    function_name[i] = function_name[i].strip()
#2
#int=1,double=2,string=3,T=4
m = input()
variable_type = []
variable_mark = {}
variable_name = []
for i in range(0,int(m)):
    str0 = input()
    variable_type.append(str0)
    data = variable_type[i].split()
    for temp in data:
        if temp=="int"or temp=="double" or temp=="string" or temp=="T":
            continue
        else:
            variable_name.append(temp)#保存变量名字
for i in range(int(m)-1):
    for j in range(int(m)-1-i):
        if len(variable_name[j])<len(variable_name[j+1]):
            variable_name[j],variable_name[j+1] = variable_name[j+1],variable_name[j]
            variable_type[j],variable_type[j+1] = variable_type[j+1],variable_type[j]

for i in range(0, int(m)):
    if variable_type[i].find("int") != -1:#看变量的类型
        variable_mark[i] = "!"
    elif variable_type[i].find("double") != -1:
        variable_mark[i] = "@"
    elif variable_type[i].find("string") != -1:
        variable_mark[i] = "#"
    elif variable_type[i].find("T") != -1:
        variable_mark[i] = "$"

#3
k = input()
example = []
for i in range(0,int(k)):
    str0 = input()
    example.append(str0)
    for j in range(0,int(m)):
        if example[i].find(variable_name[j])!=-1:
           idx = example[i].find("(")
           example[i] = example[i][:idx] + str.replace(example[i][idx:],variable_name[j],str(variable_mark[j]))
    example[i] = example[i].replace(" ","")
#######
for i in range(0,int(n)):
    if template[i].find("int")!=-1:
        template[i] = template[i].replace("int","!")
    if template[i].find("double")!=-1:
        template[i] = template[i].replace("double","@")
    if template[i].find("string")!=-1:
        template[i] = template[i].replace("string","#")
    if template[i].find("T") != -1:
        template[i] = template[i].replace("T", "$")
#######start
# for i in range(0,int(n)):
#     print(template[i])
# print('.............')
# for i in range(0,int(k)):
#     print(example[i])
for i in range(0,int(k)):
    sum = 0
    for j in range(0,int(n)):
        if len(example[i])==len(template[j]):
            for u in range(0,len(example[i])):
                if template[j][u]=="$":
                    continue
                elif template[j][u]!=example[i][u]:
                    break
                if template[j][u]==")" and example[i][u]==")":
                    sum+=1
        else:
            continue
    print(str(sum))
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值