스택인가..?
쨋든 성공률에 쫄았지만 문제는 어렵지 않았다.
물론 내가 짰지만 아직도 한창 비효율적인듯...
#include <iostream>
using namespace std;
int main() {
int testCase;
cin >> testCase;
while (testCase--) {
char str[51];
cin >> str;
int cnt = 0;
for (int i = 0; i < 50; i++) {
if (str[i] == NULL || cnt == -1) break;
else {
if (str[i] == '(') cnt++;
else cnt--;
}
}
if (cnt == 0) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
return 0;
}
쨋든 성공률에 쫄았지만 문제는 어렵지 않았다.
물론 내가 짰지만 아직도 한창 비효율적인듯...
#include <iostream>
using namespace std;
int main() {
int testCase;
cin >> testCase;
while (testCase--) {
char str[51];
cin >> str;
int cnt = 0;
for (int i = 0; i < 50; i++) {
if (str[i] == NULL || cnt == -1) break;
else {
if (str[i] == '(') cnt++;
else cnt--;
}
}
if (cnt == 0) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
return 0;
}
댓글
댓글 쓰기