我自己輸入的結果是No,但不知道為何丟測試他說我Yes,請幫我看看
#include <iostream>
#include <cstdlib>
int main() {
int n;
while(std::cin >> n) {
std::cin.get();
int i;
for(i = 0; i < n; i++) {
char ch;
int small = 0;
int middle = 0;
bool legal = true;
while(true) {
ch = std::cin.get();
if(ch == '\n') break;
switch (ch) {
case '(':
small++;
break;
case ')':
small--;
if(small < 0) legal = false;
break;
case '[':
middle++;
break;
case ']':
middle--;
if(middle < 0) legal = false;
break;
default:
break;
}
}
if(small != 0 || middle != 0) legal = false;
if(legal) std::cout << "Yes" << std::endl;
else std::cout << "No" << std::endl;
}
}
return 0;
}