백준 문제풀이

백준 10799번 - C++

diligent_gideok 2022. 4. 30. 06:27
#include <bits/stdc++.h>
using namespace std;

int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);

	stack<char> c;
	string s;
	cin >> s;
	int sum=0;
	int L[100000];
	int k=0, l = 0;
	
	for (auto t : s) {
		if (t == '(')
		{
			c.push(t);
			k++;
		}
		else if (t == ')') {
			if (c.top() == '(') {
				k--; 
				l++;
				c.pop();
			}//레이저 개수
			sum += l;
			c.pop();
		}
		if (c.empty()) {
			cout << "k=" << k << " l=" << l<<'\n';
			sum += k * l+1;
			cout << sum;
			k = 0;
			l = 0;
		}
	}
	cout << sum;
}

'백준 문제풀이' 카테고리의 다른 글

백준 1697번 - C++  (0) 2022.04.30
백준 1012번 - C++  (0) 2022.04.30
백준 4949번 - C++  (0) 2022.04.30
백준 11003번 - C++  (0) 2022.04.30
백준 10866번 - C++  (0) 2022.04.30