CF1578H.Higher Order Functions
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Helen studies functional programming and she is fascinated with a concept of higher order functions — functions that are taking other functions as parameters. She decides to generalize the concept of the function order and to test it on some examples.
For her study, she defines a simple grammar of types. In her grammar, a type non-terminal T is defined as one of the following grammar productions, together with order(T) , defining an order of the corresponding type:
- "()" is a unit type, order("()")=0 .
- "(" T ")" is a parenthesized type, order("("T")")=order(T) .
- T1 "->" T2 is a functional type, order(T1"->"T2)=max(order(T1)+1,order(T2)) . The function constructor T1 "->" T2 is right-to-left associative, so the type "()->()->()" is the same as the type "()->(()->())" of a function returning a function, and it has an order of 1 . While "(()->())->()" is a function that has an order-1 type "(()->())" as a parameter, and it has an order of 2 .
Helen asks for your help in writing a program that computes an order of the given type.
输入格式
The single line of the input contains a string consisting of characters '(', ')', '-', and '>' that describes a type that is valid according to the grammar from the problem statement. The length of the line is at most 104 characters.
输出格式
Print a single integer — the order of the given type.
输入输出样例
输入#1
()
输出#1
0
输入#2
()->()
输出#2
1
输入#3
()->()->()
输出#3
1
输入#4
(()->())->()
输出#4
2
输入#5
()->(((()->())->()->())->())
输出#5
3