#K34197. Balanced Parentheses Checker

    ID: 25256 Type: Default 1000ms 256MiB

Balanced Parentheses Checker

Balanced Parentheses Checker

In this problem, you are given multiple strings and your task is to determine if the parentheses in each string are balanced. A string is considered balanced if every opening parenthesis '(' has a corresponding closing parenthesis ')' and the pairs are properly nested. Formally, a string ( S ) is balanced if it satisfies the following conditions:

  1. For every prefix of ( S ), the number of '(' is greater than or equal to the number of ')'.
  2. The total number of '(' equals the total number of ')'.

For example, the string (()) is balanced while (() is not. Your solution should process input from standard input (stdin) and output the result for each test case on standard output (stdout), with each result on a new line.

inputFormat

The first line of input contains an integer ( T ) representing the number of test cases. The following ( T ) lines each contain a single string consisting only of the characters '(' and ')'. Note that the string may be empty.

outputFormat

For each test case, output a single line containing either "YES" if the parentheses string is balanced, or "NO" otherwise.## sample

3
()
(()
())
YES

NO NO

</p>