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.

Examples

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

OJ-ID:
CodeForces-200D

author:
Caution_X

date of submission:
20191029

tags:
字符串匹配

description modelling:
输入n个函数模型
输入m个变量
输入k个函数
问:输入的k个函数有几个符合函数模型

major steps to solve it:
用结构体存函数的函数名和变量,然后暴力匹配

warnings:
一道阅读题,题目看起来十分吓人,实际上只是个字符串匹配问题

AC code:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <string>
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define maxn 1000009
#define ll long long using namespace std; int n, m, k;
map <string, string> mp; struct cadongllas
{
int num;
string var[];
string name;
}ask[], funk[]; bool equal (cadongllas x, cadongllas y)
{
if (x.num != y.num)
return ;
if (x.name != y.name)
return ;
rep (i, , x.num)
if (x.var[i] != y.var[i] && x.var[i] != "T")
return ;
return ;
} int main ()
{
cin >> n;
rep (i, , n)
{
char blank[];
scanf ("%s", blank);
//if (blank[strlen (blank) - 1] == '(') blank[ strlen (blank) - 1] = 0; ask[i].name = string (blank); cout << ask[i].name << endl;
while ()
{
char ch = getchar ();
if (ch == '(')
break;
if (ch != ' ')
ask[i].name += ch;
}
//cout << ask[i].name << endl;
string s;
getline (cin, s);
int len = s.length ();
int now = ;
while ()
{
while ((s[now] == ')' || s[now] == ',' || s[now] == ' ' ) && now < len)
now++;
if (now >= len)
break;
string nex;
while ()
{
nex += s[now++];
if (s[now] == ')' || s[now] == ',' || s[now] == ' ' || now >= len)
break;
}
ask[i].var[ ++ ask[i].num] = nex;
//cout << "----" << nex << endl;
if (s[now] == ')')
break;
}
}
//rep (i, 1, n) { printf ("%d %d\n", i, ask[i].num); rep (j, 1, ask[i].num) cout << ask[i].var[j] << endl; }
cin >> m;
rep (i, , m)
{
string sa, sb;
cin >> sa >> sb;
mp[sb] = sa;
}
cin >> k;
getchar ();
rep (i, , k)
{
while ()
{
char ch = getchar ();
if (ch == '(')
break;
if (ch != ' ')
funk[i].name += ch;
}
//cout << "name" << funk[i].name << endl;
string s;
getline (cin, s);
int len = s.length (), now = ;
while ()
{
while ((s[now] == ')' || s[now] == ',' || s[now] == ' ' ) && now < len)
now++;
if (now >= len)
break;
string nex;
while ()
{
nex += s[now++];
if (s[now] == ')' || s[now] == ',' || s[now] == ' ' || now >= len)
break;
}
funk[i].var[ ++ funk[i].num] = mp[nex];
//cout << "----" << nex << endl;
if (s[now] == ')')
break;
}
//rep (p, 1, funk[i].num) cout << "===" << funk[i].var[p] << "===" << endl; int ans = ;
rep (j, , n)
if (equal (ask[j], funk[i]))
ans++;
cout << ans << endl;
}
return ;
}

最新文章

  1. Centos7 防火墙简介(一)
  2. [Python] 学习资料汇总
  3. js判断输入时间是否大于系统时间
  4. linux命令连接远程服务器
  5. 让禅道也可以玩BearyChat
  6. 基于DDD的.NET开发框架 - ABP仓储实现
  7. html+css+javascript实现列表循环滚动示例代码
  8. pageContext对象的用法
  9. jsp福利哟
  10. [App]Xamarin First(Or Last One) App
  11. Console 程序在任务计划程序无法读写文件
  12. java 继承与多态
  13. UVALive 6887 Book Club
  14. vue插件编写与实战
  15. Android4.0新控件
  16. 剑指架构师系列-持续集成之Maven+Nexus+Jenkins+git+Spring boot
  17. SQL随记(六)
  18. Expression的烦恼
  19. net基础语法
  20. v-charts使用心得

热门文章

  1. ES6 ES7 ES8 相关用法
  2. flex布局使用
  3. javascript es6 Promise 异步同步的写法(史上最简单的教程了)
  4. PHP实现微信提现(企业付款到零钱)
  5. SpringCloud微服务(04):Turbine组件,实现微服务集群监控
  6. SpringBoot2.0 整合 SpringSecurity 框架,实现用户权限安全管理
  7. PAT 1010 Radix 进制转换+二分法
  8. Windows应急日志常用的几个事件ID
  9. 039.[转] 基于 Kubernetes 和 Spring Cloud 的微服务化实践
  10. MySQL 优化 (二)