-
Notifications
You must be signed in to change notification settings - Fork 0
/
괄호 회전하기.cpp
36 lines (36 loc) · 929 Bytes
/
괄호 회전하기.cpp
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
29
30
31
32
33
34
35
36
#include <string>
#include <vector>
#include <deque>
#include <stack>
using namespace std;
bool check_correct(deque<char> temp){
stack<char> s;
for(int i=0; i<temp.size(); i++){
if(s.empty())
s.push(temp[i]);
else{
if((s.top() == '(' && temp[i] == ')') || (s.top() == '{' && temp[i] == '}') || (s.top() == '[' && temp[i] == ']'))
s.pop();
else
s.push(temp[i]);
}
}
return (s.empty() ? true : false);
}
int solution(string s) {
int answer = 0;
deque<char> container;
for(int i=0; i<s.size(); i++){
container.push_back(s[i]);
}
deque<char> original = container;
for(int i=0; i<s.size(); i++){
if(check_correct(container)){
answer++;
}
char c = container.front();
container.pop_front();
container.push_back(c);
}
return answer;
}