Codeforces-200dprogramming Language Pure Simulation

Source: Internet
Author: User

codeforces-200dProgramming Language
Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %i64d &%i64u

Submit Status

Description

Recently, Valery has come across an entirely new programming language. Most of the language attracted him with template functions and procedures. Let us remind templates is 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 the If the following conditions is 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 Variab Le and the parameter are the same.

You are given a description of some set of template procedures. You is also given a list of variables used in the program, as well as direct procedure calls that use the described Varia Bles. Need to count the number of procedures that is suitable for the.

Input

The first line contains a integer  n   (1?≤? N ? ≤?1000 )-the number of the 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, and Var_i is the name of a variable.

The lines describing the variables, template procedures and their calls may contain spaces at the beginning And at the end of the line, before and after the brackets and commas. Spaces May is before and after Keyword void . The length of each input line does not exceed100   Characters. The names of variables and procedures are non-empty strings of lowercase 中文版 letters and numbers with lengths of not M Ore than 10  characters. Note that this is the only condition at the names. Only the specified variables is used in procedure calls. The names of the variables is distinct. No. Procedures is the same. Procedures is the same, if they has identical names and identical ordered sets of types of their parameters.

Output

On each of the K lines print a single number, where the i-th number stands for the number of suitable templa Te procedures for the I-th call.

Sample Input

Input
4void f (int,t) void  F (t, T) void foo123   (int,  double,  string,string  )  void  P (t,double) 3int a string    sdouble x123 5f (A,  a) f (s,a   ) foo   (a,s,s) F  (  s  , x123) proc (a)
Output
21010
Input
6void 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 xstring  tdouble  val 5f (T, A, a) f (t,val,a) F (Val,a, Val) solve300 (Val, Val) f< c20/> (x)
Output
13002

Source

Codeforces Round #126 (Div. 2) This topic first tells everybody, must have the patience now to say I question-solving mentality, may trouble, if has the big God floated, asks the guidance first to turn void f (int, T) into VOIDF (int,t) to remove all the blanks, Then remove the first four of the string because void is not the function name, and the function name is on the left. And then the other deals are similar simulations.
/*author:2486memory:256 kbtime:62 mslanguage:gnu g++ 4.9.2result:accepted*/#include <cstdio> #include <cstri ng> #include <algorithm> #include <vector> #include <map> #include <string> #include <    iostream>using namespace Std;const int maxn=1000+5;struct func {char name[100+5]; Vector<int>g;} Funcs[maxn];int N,m;map<string,int>f;map<string,bool>ks;char str[maxn];void Getgs (char *st,int l) {int cn    t=0;        for (int i=0; i<l; i++) {if (st[i]!= ") {st[cnt++]=st[i]; }} st[cnt]= ' + ';}    void Getsg (char *st,int ID) {int l=strlen (ST);    int cnt=0;        for (int i=4, i<l; i++) {if (st[i]== ' (') break;    Funcs[id].name[cnt++]=st[i];    } funcs[id].name[cnt]= ' + '; for (int i=cnt+4; i<l; i++) {if (str[i-1]== ' n ' &&st[i]== ' t ') {Funcs[id].        G.push_back (1); } else if (str[i-1]== ' d ' &&st[i]== ' O ') {Funcs[id].        G.push_back (2); } ElSe if (str[i-1]== ' s ' &&st[i]== ' t ') {Funcs[id].        G.push_back (3); } else if (str[i]== ' T ') {Funcs[id].        G.push_back (4);    }}}int getsgs (char *st) {func s;    int L=strlen (ST);    int cnt=0;        for (int i=0, i<l; i++) {if (st[i]== ' (') break;    S.name[cnt++]=st[i];    } s.name[cnt]= ' + '; if (!    Ks[s.name]) return 0;    Char op[100+5];    int sf=0; for (int i=cnt+1; i<l; i++) {if (st[i]== ', ' | | |            st[i]== ') ' {op[sf]= ';            S.g.push_back (F[op]);            sf=0;        Continue    } Op[sf++]=st[i];    } int res=0;    BOOL Flag;            for (int i=0; i<n; i++) {if (strcmp (funcs[i].name,s.name) ==0) {flag=true; if (S.g.size ()!=funcs[i].            G.size ()) continue; for (int j=0; j<s.g.size (); j + +) {if (Funcs[i].                G[J]==4) continue; if (Funcs[i].                    G[j]!=s.g[j]) {flag=false;                Break   }         } if (flag) res++; }} return res;}    int main () {//freopen ("D://imput.txt", "R", stdin);    scanf ("%d", &n);        for (int i=0; i<n; i++) {gets (str);        int L=strlen (str);            if (l==0) {i--;        Continue        } GETGS (str,l);        GETSG (Str,i);    Ks[funcs[i].name]=1;    } scanf ("%d", &m);    Char op[10],ops[100+5];        for (int i=0; i<m; i++) {scanf ("%s%s", op,ops);        if (op[0]== ' d ' &&op[1]== ' O ') {f[ops]=2;        } else if (op[0]== ' i ' &&op[1]== ' n ' &&op[2]== ' t ') {f[ops]=1;        } else if (op[0]== ' s ' &&op[1]== ' t ') {f[ops]=3;    }} scanf ("%d", &m);        for (int i=0; i<m; i++) {gets (str);        int L=strlen (str);            if (l==0) {i--;        Continue        } GETGS (str,l);    printf ("%d\n", Getsgs (str)); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces-200dprogramming Language Pure Simulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.