#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <string.h>

using namespace std;

int main(){
	string s;
    cin >> s;

    char before = s[0];
    vector< pair<int,bool> > steel_num(1,make_pair(1, true));
	for(int i = 1; i< s.length(); i++){
        if(s[i] == '('){
            steel_num.push_back(make_pair(1,true));
        }
        else if(s[i] == ')'){
            if(before == '('){  //레이저일때
                steel_num.pop_back();
                for(int j = 0; j<steel_num.size(); j++){
                    if(steel_num[j].second == true)
                        steel_num[j].first++;
                }
            }
            else{
                for(int j = steel_num.size()-1; j >= 0; j--){
                    if(steel_num[j].second == true){
                        steel_num[j].second = false;
                        break;
                    }
                }
            }
        }
        before = s[i];
	}
	int result = 0;
    for(int i = 0; i<steel_num.size(); i++){
        //cout<<steel_num[i].first<<" ";
        result += steel_num[i].first;
    }
    cout<<result<<endl;

    return 0;
}

'컴퓨터 > 문제 풀기' 카테고리의 다른 글

백준 1946번 신입 사원  (0) 2019.05.20
백준 16955번 오목, 이길 수 있을까?  (0) 2019.05.20
2413번 비슷한 순열  (1) 2019.05.13
2309번 일곱 난쟁이  (0) 2019.05.13
백준 1780번 종이의 개수  (0) 2019.05.13

+ Recent posts