308120: CF1469A. Regular Bracket Sequence

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Regular Bracket Sequence

题意翻译

多测。 给定一个包含 `(`,`)`,`?` 三种字符的字符串,并且保证只有一个 `(` 和一个 `)` 。 其中你可以将 `?` 替换成 `(` or `)`。 问是否存在一种替换方案,使得替换后的串左右括号匹配。 注意 `?` 必须得替换掉,最后留下的必须是个括号串。 存在输出一行 `YES`,否则输出一行 `NO`。

题目描述

A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters + and 1 into this sequence. For example, sequences (())(), () and (()(())) are regular, while )(, (() and (()))( are not. Let's call a regular bracket sequence "RBS". You are given a sequence $ s $ of $ n $ characters (, ), and/or ?. There is exactly one character ( and exactly one character ) in this sequence. You have to replace every character ? with either ) or ( (different characters ? can be replaced with different brackets). You cannot reorder the characters, remove them, insert other characters, and each ? must be replaced. Determine if it is possible to obtain an RBS after these replacements.

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 1000 $ ) — the number of test cases. Each test case consists of one line containing $ s $ ( $ 2 \le |s| \le 100 $ ) — a sequence of characters (, ), and/or ?. There is exactly one character ( and exactly one character ) in this sequence.

输出格式


For each test case, print YES if it is possible to obtain a regular bracket sequence, or NO otherwise}. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

输入输出样例

输入样例 #1

5
()
(?)
(??)
??()
)?(?

输出样例 #1

YES
NO
YES
YES
NO

说明

In the first test case, the sequence is already an RBS. In the third test case, you can obtain an RBS as follows: ()() or (()). In the fourth test case, you can obtain an RBS as follows: ()().

Input

题意翻译

多测。 给定一个包含 `(`,`)`,`?` 三种字符的字符串,并且保证只有一个 `(` 和一个 `)` 。 其中你可以将 `?` 替换成 `(` or `)`。 问是否存在一种替换方案,使得替换后的串左右括号匹配。 注意 `?` 必须得替换掉,最后留下的必须是个括号串。 存在输出一行 `YES`,否则输出一行 `NO`。

加入题单

上一题 下一题 算法标签: