https://www.acmicpc.net/problem/9012
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void){
int n;
vector<string> v;
cin >> n;
int size_ = 0;
string str;
for (int i=0;i<n;i++){
cin>>str;
size_ = 0;
for(int j=0;j<str.size();j++){
if (str[j] == '(') size_ +=1 ;
else if (str[j] == ')') size_ -=1 ;
if (size_ < 0) {
v.push_back("NO");
break;
}
}
if (size_ == 0) v.push_back("YES");
else if (size_ > 0) v.push_back("NO");
}
for(vector<string>::iterator iter = v.begin(); iter!=v.end();iter++){
cout<<*iter<<"\n";
}
}
- no, yes 판단해서 바로바로 출력하면 틀렸습니다 결과가 나와서 따로 벡터에 저장한 후 출력함
'자기개발👨💻 > 코딩 알고리즘' 카테고리의 다른 글
[C++] 백준 1158 요세푸스 문제 //<queue> (0) | 2022.03.18 |
---|---|
[C++] 백준 11651 // <vector><map> (0) | 2022.03.16 |
[C++] 백준 1302 베스트셀러 // <map> (0) | 2022.03.16 |
[C++] 프로그래머스 더 맵게 (0) | 2022.03.13 |
[C++] 백준 1448 삼각형 만들기 (0) | 2022.02.28 |
[C++] 백준 2309 일곱 난쟁이 (0) | 2022.02.27 |