https://www.acmicpc.net/problem/10799
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int CountIronStickPieces(const string& input)
{
stack<char> st;
int totalPieces = 0;
for (size_t i = 0; i < input.length(); ++i)
{
if (input[i] == '(')
{
st.push('(');
}
else // ')'
{
st.pop(); // 짝이 맞는 '(' 제거
if (input[i - 1] == '(')
{
// 레이저: 현재 쌓여 있는 막대기 수만큼 조각 추가
totalPieces += st.size();
}
else
{
// 쇠막대기 끝: 조각 하나 추가
totalPieces += 1;
}
}
}
return totalPieces;
}
int main()
{
string input;
cin >> input;
cout << CountIronStickPieces(input) << endl;
return 0;
}
백준 4963 섬의 개수 (0) | 2025.04.08 |
---|---|
백준 2559 (0) | 2025.04.05 |
백준 //안전 영역 (0) | 2025.04.04 |
프로그래머스 바탕화면 정리 (0) | 2025.04.03 |
소수 구하기//백준 (0) | 2025.03.31 |