-
10799) 쇠막대기 c++백준코딩일기 2020. 11. 17. 10:37
문제 ) www.acmicpc.net/problem/10799
10799번: 쇠막대기
여러 개의 쇠막대기를 레이저로 절단하려고 한다. 효율적인 작업을 위해서 쇠막대기를 아래에서 위로 겹쳐 놓고, 레이저를 위에서 수직으로 발사하여 쇠막대기들을 자른다. 쇠막대기와 레이저
www.acmicpc.net
풀이 )
코드 )
#include <iostream> #include <stack> using namespace std; stack<int> s; string input; int ans; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> input; for(int index = 0; index < input.length(); index++) { if( input[index] == '(' ) s.push(index); else { if( s.top()+1 == index) { s.pop(); ans += s.size(); } else { ans += 1; s.pop(); } } } cout << ans; }
'백준코딩일기' 카테고리의 다른 글
4889) 안정적인 문자열 c++ (0) 2020.11.17 2504) 괄호의 값 c++ (0) 2020.11.17 4949) 균형잡힌 세상 c++ (0) 2020.11.17 10828) 스택 c++ (0) 2020.11.05 1158) 요세푸스 문제 (0) 2020.11.05