아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Don’t Complicate It!

면접 대비

시간 제한1초메모리 제한1024 MB

요약
공백이 섞일 수 있는 올바른 괄호 문자열이 주어질 때, 각 괄호 쌍의 중첩 깊이에 따라 정해진 값을 모두 더해 복잡도를 구한다.
난이도

보통10점 중 4점

유형
스택, 문자열
정답자
아직 제출이 없습니다

문제

The number of parentheses and the level of nesting are usually a good indication of how complicated an expression is.

Given a string containing only “(”, “)” and blanks (spaces), compute its complexity. The complexity is defined as follows:

  • Each innermost set of parentheses adds 1 to the total complexity.
  • Each set of parentheses containing only innermost set of parentheses adds 2 to the total complexity, i.e., one level out will add 2 to the complexity.
  • Each set of parentheses at the next level out adds 3 to the complexity, and so on.

입력

There is only one input line; it contains a valid expression. The expression (string) will be 2-60 characters, each character being either “(”, “)” or blank (space). Note that the blanks can be anywhere but the string will not exceed 60 characters (including the blanks). Assume that there will be at least one set of parentheses in the input, i.e., the input will not be all blanks.

Note that a valid expression satisfies the following:

  1. All the parentheses are matched, i.e., every opening parenthesis has a corresponding closing parenthesis.
  2. The matched parentheses are in the correct order, i.e., an opening parenthesis comes before its corresponding closing parenthesis.

Note again that the input is a valid expression, i.e., you do not need to check for errors.

출력

Print the complexity of the expression.

힌트

Note: The last Sample Input has parentheses nested 20 levels.

예제5

  1. 예제 1

    입력
    ()()()()()
    
    예상 출력
    5
    
  2. 예제 2

    입력
            ( () ( ) () ( ) )
    
    예상 출력
    6
    
  3. 예제 3

    입력
    ( (()) () (()) )
    
    예상 출력
    10
    
  4. 예제 4

    입력
         ((())) () ( (()) () (()) )
    
    예상 출력
    17
    
  5. 예제 5

    입력
    (((((((((((((((((((())))))))))))))))))))
    
    예상 출력
    210