백준 10799 c++

magicdrill·2024년 3월 25일

백준 문제풀이

목록 보기
206/675

백준 10799 c++

#include <iostream>
#include <vector>
#include <stack>
#include <string>

using namespace std;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int i, result = 0;
	stack <char> st;
	string str;
	
	cin >> str;
	for (i = 0; i < str.length(); i++)
	{
		if (str[i] == '(') // (인 경우
		{
			st.push('(');
		}
		else// )인 경우
		{
			if (str[i - 1] == '(')//컷팅
			{
				st.pop();
				result += st.size();
			}
			else
			{
				st.pop();
				result++;
			}
		}
	}
	cout << result << "\n";

	return 0;
}

0개의 댓글