Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 수학
- 브루트포스
- 투 포인터
- 백준
- 유니온 파인드
- 자료구조
- 백트래킹
- 구현
- 스택
- 우선순위 큐
- 재귀
- Unreal Engine 5
- 문자열
- 그리디 알고리즘
- 정렬
- c++
- 다익스트라
- Team Fortress 2
- XR Interaction Toolkit
- 알고리즘
- 트리
- 누적 합
- DFS
- ue5
- BFS
- 다이나믹 프로그래밍
- 시뮬레이션
- 그래프
- 유니티
- VR
Archives
- Today
- Total
1일1알
백준 10799번 쇠막대기 C++ 본문
() 일 때 : 레이저
(~~) 일 때 : 쇠막대기
()가 들어왔을 때 앞에있는 (의 개수만큼 잘린다.
쇠막대기의 끝에서는 한번 더 잘리기 때문에 긴 괄호가 닫힐 때에는 cnt에 1을 더해준다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string str;
cin >> str;
stack<char> st;
int cnt = 0;
bool flag = false;
for (int i = 0; i < str.length(); i++) {
if (str[i] == ')') {
st.pop();
if (flag) cnt += st.size();
else cnt++;
flag = false;
}
else {
flag = true;
st.push(str[i]);
}
}
cout << cnt;
};
'알고리즘' 카테고리의 다른 글
백준 10815번 숫자 카드 C++ (0) | 2022.06.03 |
---|---|
백준 1158번 요세푸스 문제 C++ (0) | 2022.06.02 |
백준 17298번 오큰수 C++ (0) | 2022.05.31 |
백준 2573번 빙산 C++ (0) | 2022.05.30 |
백준 2644번 촌수계산 C++ (0) | 2022.05.29 |