CodeForces 200D 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.
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
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)
2
1
0
1
0
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)
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 ;
}
CodeForces 200D Programming Language的更多相关文章
- iOS Swift-元组tuples(The Swift Programming Language)
iOS Swift-元组tuples(The Swift Programming Language) 什么是元组? 元组(tuples)是把多个值组合成一个复合值,元组内的值可以使任意类型,并不要求是 ...
- iOS Swift-控制流(The Swift Programming Language)
iOS Swift-控制流(The Swift Programming Language) for-in 在Swift中for循环我们可以省略传统oc笨拙的条件和循环变量的括号,但是语句体的大括号使我 ...
- iOS Swift-简单值(The Swift Programming Language)
iOS Swift-简单值(The Swift Programming Language) 常量的声明:let 在不指定类型的情况下声明的类型和所初始化的类型相同. //没有指定类型,但是初始化的值为 ...
- Java Programming Language Enhancements
引用:Java Programming Language Enhancements Java Programming Language Enhancements Enhancements in Jav ...
- The Swift Programming Language 英文原版官方文档下载
The Swift Programming Language 英文原版官方文档下载 今天Apple公司发布了新的编程语言Swift(雨燕)将逐步代替Objective-C语言,大家肯定想学习这个语言, ...
- The Swift Programming Language 中文翻译版(个人翻新随时跟新)
The Swift Programming Language --lkvt 本人在2014年6月3日(北京时间)凌晨起来通过网络观看2014年WWDC 苹果公司的发布会有iOS8以及OS X 10.1 ...
- [iOS翻译]《The Swift Programming Language》系列:Welcome to Swift-01
注:CocoaChina翻译小组已着手此书及相关资料的翻译,楼主也加入了,多人协作后的完整译本将很快让大家看到. 翻译群:291864979,想加入的同学请进此群哦.(本系列不再更新,但协作翻译的进度 ...
- Questions that are independent of programming language. These questions are typically more abstract than other categories.
Questions that are independent of programming language. These questions are typically more abstract ...
- What is the Best Programming Language to Learn in 2014?
It’s been a year since I revealed the best languages to learn in 2013. Once again, I’ve examined the ...
随机推荐
- Cocos2d-x3.0网络通信学习(一)
配置:win7+Cocos2d-x.3.0+VS2012 摘要:建立基本的http通信并得到返回信息. 一.添加项目与编译库 1.添加头文件 在需要用到Http网络相关类的文件中加入头文件 #incl ...
- 小程序之--动态设置页面标题 wx.setNavigationBarTitle
参考地址 http://www.yilingsj.com/xwzj/2018-11-26/weixin-navigationbartitletext.html 页面最初是[在线教研] 可以在这个页面的 ...
- nginx基础(1)
目录 一.概念 基础概念 响应码 请求和响应报文的格式 http无连接 我叫张贺,贪财好色.一名合格的LINUX运维工程师,专注于LINUX的学习和研究,曾负责某中型企业的网站运维工作,爱好佛学和跑步 ...
- pytorch中的nn.CrossEntropyLoss()
nn.CrossEntropyLoss()这个损失函数和我们普通说的交叉熵还是有些区别 x是模型生成的结果,class是对应的label 具体代码可参见如下 import torch import t ...
- ubuntu 18.04多应用窗口切换的快捷键使用指南
前记 使用ubuntu时间长了,很厌烦用鼠标来点来点去.重复操作的,还是快捷键比较方便.在多窗口切换方面,熟悉了几个快捷键之后,顿时感觉神清气爽.这里就推荐给大家学习一下,提高工作效率啊. 常用快捷键 ...
- C语言程序设计100例之(20):过河卒
例20 过河卒 题目描述 如图1,在棋盘的A点有一个过河卒,需要走到目标B点.卒行走规则:可以向下.或者向右.同时在棋盘上的任一点有一个对方的马(如图1的C点),该马所在的点和所有跳跃一步可达的点称 ...
- DEBUG 命令用法
(2)DEBUG 命令用法 进入 DEBUG ,用 D 命令查看数据段中 0100H——0200H 单元的内容 用 U 命令查看代码段中 0100H 开始的程序 用 R 命令查看并修改 IP 寄存器的 ...
- adb devices无法连接mumu模拟器
解决方案: 如果你的android环境能够直接访问 adb 的相关指令.只需要把mumu模拟器打开 然后打开cmd -> 输入 adb connect 127.0.0.1:7555 就能直接连上 ...
- 【开发工具】本机安装的JDK8,启动IDEA2019没反应
问题描述 本来开发工具安装的是IDEA2018,有天用着用着突然崩溃了,重启后死活用不了.心血来潮下载了2019版本,顺利安装完,但是点击快捷方式启动的时候一直没反应.后来咨询同事,在下面的启动脚本中 ...
- 传统jdbc存在的问题总结
1.数据库连接创建.释放频繁造成系统资源浪费,影响系统性能,可使用数据库连接池解决此问题. 2.sql语句中在代码中硬编码,代码不易维护,sql变动需要改变java代码. 3.使用preparedSt ...