#include <iostream>
#include <stack>
#include <sstream>
using namespace std;
int main() {
string input;
cin >> input;
int pipe = 0;
stack <char> s;
for(int i = 0 ; i < input.length(); i++)
{
if(input[i] == '(' && input[i+1] == ')')
{
pipe += s.size();
i++;
}
else if(input[i] == '(')
{
s.push(input[i]);
}
else if(input[i] == ')')
{
pipe++;
s.pop();
}
}
cout << pipe;
return 0;
}
'프로그래밍 공부 > 백준 (C++)' 카테고리의 다른 글
[C++/백준 17298번] 오등큰수 (0) | 2024.10.24 |
---|---|
[C++/백준 17298번] 오큰수 (0) | 2024.10.24 |
[C++ / 백준 17413번] 단어 뒤집기 2 (0) | 2024.10.14 |
[C++/백준 10866번] 덱 (0) | 2024.10.12 |
[C++/백준 1158번] 요세푸스 문제 (0) | 2024.10.12 |