Skip to content

Instantly share code, notes, and snippets.

@HyeonWooKim
Created February 26, 2016 18:08
Show Gist options
  • Save HyeonWooKim/430bf9658215f7134ace to your computer and use it in GitHub Desktop.
Save HyeonWooKim/430bf9658215f7134ace to your computer and use it in GitHub Desktop.
스택을 이용한 BOJ 9012 풀이
#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