Source: this one became infamous as was proposed by Yandex in their application form for Junior QA (automation) position during years 2009-2018.
It is a simple problem, you just need to get acquainted with Backus-Naur form if you never heard of it before.
Subroutine declarations in some programming language are described by the following syntactic rules:
<subroutine declaration> ::= <procedure declaration> | <function declaration>
<procedure declaration> ::= procedure <identifier> <formal arguments> ;
<function declaration> ::= function <identifier> <formal arguments> : <type> ;
<formal arguments> ::= ( <argument list> | )
<argument list> ::= <argument section> { ; <argument section> }
<argument section> ::= <identifier> { , <identifier> } : <type>
<identifier> ::= <letter|_>{<letter>|<digit>|_}
<type> ::= integer | real | boolean
We do not include definitions for letter
and digit
as they seem obvious (e.g. A..Z | a..z
and 0..9
respectively,
but in BNF it is more verbose). The character _
is an underscore. Note that spaces (and tabs) can be inserted anywhere except inside
identifiers.
You are to write simple syntax analyzer which checks whether given string satisfies the given rules (i.e. is correct subroutine declaration).
Input: The first line gives N
- number of strings to follow.
Next lines contain one declaration each.
Output: Print numbers of lines which contain correct declarations, space-separated, counting from 1
.
Example:
input:
4
function hypot(a, b: real): real;
procedure setxy(x integer, y integer);
procedure stop();
function is_round(x: real; y: integer);
output:
1 3