ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

NEERC 2011, Eastern subregional contest

About     Problems     Submit solution     Judge status     Standings
Contest is over

G. Language Ocean

Time limit: 1.0 second
Memory limit: 64 MB
Engineers from the Oceanic Airlines company have proposed to write software for airplane equipment using the new, very simple, and efficient programming language Ocean.
This language has only three data types: int, real, and string. Each program starts with a list of function headers in which all the functions used in the program must be mentioned. A function header has the form
  • <function name>(<type of arg 1>, ..., <type of arg k>) : <type of the result>
A function may have no arguments. The names of different functions may coincide.
The text of the main program is a list of variable declarations together with their initializations. Each line of the program has the form
  • <variable type> <variable name> = <function name>(<arg 1>, ..., <arg k>)
For a programmer's convenience, the variable type can be replaced with the keyword auto, which means that the variable type is defined by the type of the value returned by the function. When a function is called, the names of previously declared variables are specified as its arguments. If there are several functions with the specified name, then a function will be called in which the number of arguments and their types correspond to the function call. The name of a variable may coincide with the name of some function.
Employees of Oceanic Airlines ask you to write an interpreter of the Ocean language. The interpreter must check each line of the main program searching for the following errors (in the following order):
  1. “Double declaration” — a variable with this name has already been declared;
  2. “Unknown variable” — the name of one of the arguments hasn't been declared in previous lines;
  3. “No such function” — there is no function with this name and a suitable list of arguments;
  4. “Invalid initialization” — the type of the returned value does not correspond to the type of the variable.


The first line contains the number f of function headers (1 ≤ f ≤ 100). The headers are given in the following f lines. Any two functions differ either by their names or by the lists of their arguments. In the following line you are given the number n of lines in the main program (1 ≤ n ≤ 100). Each of the following n lines contains a variable declaration and its initialization. Each function header and each function call contains at most 10 arguments. The names of variables and functions have lengths from 1 to 20 symbols. Names of the variables consist of lowercase English letters, whereas names of the functions may also contain uppercase English letters. The names of functions differing by letter cases only are considered to be different. The strings “int”, “real”, “string”, and “auto” cannot be names of variables or functions. Spacing is as in the input data samples.


If there are no errors in the program, output the list of all variables declared as “auto” and their types. The variables should be given in the order in which they are declared in the program. If there are errors in the program, output the number of the line containing the first error and the type of the error. The format of the output should correspond to the samples.


ReadInt() : int
IntToReal(int) : real
auto a = ReadInt()
auto b = IntToReal(a)
int c = ReadInt()
a : int
b : real
ReadInt() : int
int x = ReadInt()
int x = ReadInt()
Error on line 2: Double declaration
ReadInt() : int
ReadReal() : real
SumRealInt(real, int) : real
auto x = ReadInt()
auto y = ReadReal()
real z = SumRealInt(y, x)
real q = SumRealInt(x, y)
Error on line 4: No such function
Problem Author: Alex Samsonov
Problem Source: NEERC 2011, Eastern subregional contest
To submit the solution for this problem go to the Problem set: 1891. Language Ocean