题目 题意:给定一个只含一个(和),其他都是?的字符串,现在将?替换成(或),问能否凑成合法序列。 思路:首先要是偶数个字符;其次,只要保证)不在首位,(不在末位即可。
#include
using namespace std;
#define ll long long
const int maxn = 1010;
char s[maxn];
int n;
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%s", s);
n = strlen(s);
if (s[0] == ')' || s[n-1] == '(' || (n % 2 == 1)) {
printf("NO\n");
} else {
printf("YES\n");
}
}
}