File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+
2+
3+ int main () {
4+ cout << solution (" [](){}" );
5+ cout << solution (" }]()[{" );
6+ cout << solution (" [)(]" );
7+ return 0 ;
8+ }#include <string>
9+ #include < vector>
10+ #include < stack>
11+ #include < iostream>
12+ using namespace std ;
13+
14+ bool check (string s) {
15+ stack<char > st;
16+ bool flag = false ;
17+
18+ for (int i = 0 ; i < s.length (); i++) {
19+ if (s[i] == ' (' )
20+ st.push (' (' );
21+ else if (s[i] == ' {' )
22+ st.push (' {' );
23+ else if (s[i] == ' [' )
24+ st.push (' [' );
25+ else
26+ {
27+ if (!st.empty ()) {
28+ flag = true ;
29+ if (st.top () == ' (' && s[i] == ' )' )
30+ st.pop ();
31+ else if (st.top () == ' {' && s[i] == ' }' )
32+ st.pop ();
33+ else if (st.top () == ' [' && s[i] == ' ]' )
34+ st.pop ();
35+ else
36+ st.push (s[i]);
37+ }
38+ }
39+ }
40+ if (st.empty () && flag)
41+ return true ;
42+ else
43+ return false ;
44+ }
45+
46+ int solution (string s) {
47+ int answer = 0 ;
48+
49+ for (int i = 0 ; i < s.length (); ++i) {
50+ s += s[0 ];
51+ s = s.substr (1 , s.length () - 1 );
52+
53+ if (check (s))
54+ ++answer;
55+ }
56+
57+ return answer;
58+ }
Original file line number Diff line number Diff line change 202202 <ClCompile Include =" Lv2\Lv2_괄호변환.cpp" >
203203 <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >true</ExcludedFromBuild >
204204 </ClCompile >
205+ <ClCompile Include =" Lv2\Lv2_괄호회전하기.cpp" >
206+ <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >true</ExcludedFromBuild >
207+ </ClCompile >
205208 <ClCompile Include =" Lv2\Lv2_구명보트.cpp" >
206209 <ExcludedFromBuild Condition =" '$(Configuration)|$(Platform)'=='Debug|x64'" >true</ExcludedFromBuild >
207210 </ClCompile >
Original file line number Diff line number Diff line change 546546 <ClCompile Include =" Lv2\Lv2_순위검색.cpp" >
547547 <Filter >소스 파일</Filter >
548548 </ClCompile >
549+ <ClCompile Include =" Lv2\Lv2_괄호회전하기.cpp" >
550+ <Filter >소스 파일</Filter >
551+ </ClCompile >
549552 </ItemGroup >
550553</Project >
You can’t perform that action at this time.
0 commit comments