Created
February 26, 2016 18:08
-
-
Save HyeonWooKim/430bf9658215f7134ace to your computer and use it in GitHub Desktop.
스택을 이용한 BOJ 9012 풀이
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
using namespace std; | |
int top; | |
int main(){ | |
int cases; | |
cin>>cases; | |
while(cases--){ | |
string s; | |
bool valid=true; | |
cin>>s; | |
int length = s.length(); | |
//0:여는 괄호, 1:닫는 괄호 | |
for(int i=0;i<length;i++){ | |
if(s[i]=='(') top++; | |
else if(s[i]==')'){ | |
if(top==0){ | |
valid=false; | |
break; | |
} else top--; | |
} | |
} | |
if(top!=0) valid=false; | |
cout<<(valid==true?"YES\n":"NO\n"); | |
top=0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment