We need to solve the problem: Given a string S consisting only of '(' and ')'? Actually problem description says "bracket ratio" and brackets, likely the string contains only '(' and ')'. But not explicitly; it says "brackets in the given string". It could be that the string contains only parentheses. In examples, only parentheses. But constraints: length up to 60, T up to 10. So we need to check if parentheses are balanced.
But typical problem: check balanced parentheses using stack or counter. Conditions: For each character, if '(' increment counter, if ')' decrement. If counter goes negative at any point -> invalid. At end, counter must be 0.
But careful: there might be other characters? Problem says "string to be checked" for brackets. Could be any characters? Probably only '(' and ')', but to be safe we can ignore other characters. However typical competitive programming problem "Brackets" might include other characters; but they said "brackets in the given string", so we only care about parentheses. I'd assume only '(' and ')'.
Implement: For each test case, read string S. Use balance = 0, for char c in S: if c == '(' balance++; if c == ')' then if balance == 0: invalid else balance--; after loop, if balance == 0: YES else NO.
Edge cases: empty string? length >=1 so fine.
Input reading: first integer T. Then for each test case, read a line containing the string. Might be spaces? Not likely. We'll just read with input().
Now produce solution in C? The user likely expects code. The conversation is: They gave problem description and ask to solve. We need to provide a solution code and explanation? The prompt: "You are an AI programming assistant, respond only with code solution in requested language." Actually full instructions: "You are an AI programming assistant. Provide the final answer code solution in the requested language. You must not include any other text or explanation." So we must output only the code solution. And language? Not specified, but typical is C++? Could be any. The problem is from CodeChef? Often they accept multiple. But they didn't specify. Usually for such problems, they expect C++ or maybe C. We'll assume C++? The user didn't specify language. Looking at the conversation: They said "Problem description." and then input/output etc. The assistant is supposed to respond with code. But the system message says: "You are an AI programming assistant. Provide the final answer code solution in the requested language." Since no language requested, perhaps we need to ask? But we are to respond only with code. In many CodeChef discussions, they might expect C++. I'll provide a C++ solution using stack or counter. Keep it simple.
I'll output:
#include
#include
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int bal = 0;
bool ok = true;
for (char c : s) {
if (c == '(') bal++;
else if (c == ')') {
if (bal == 0) {
ok = false;
break;
}
bal--;
}
}
if (ok && bal == 0) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
But need to handle newline after reading t? cin >> t will read integer and leave newline, then cin >> s will read next token (skipping whitespace) so it's fine as string without spaces.
But the string may contain spaces? Not likely. If it did, cin would only read up to space. However problem says string S; presumably no spaces. Good.
Alternatively, we could use getline to be safe but not needed.
Thus final answer: code in C++. Since language not specified, I'll provide C++. If they expected Python, they'd say. But we'll output C++ code as typical.
But note the user message: "Problem description." That's it. Possibly they want solution. Since they didn't specify language, we could provide multiple? But instruction says only code. So I'll output C++.
I think it's okay.
But let's double-check the problem: "Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world." It might be that the string contains only '(' and ')'? Usually these problems have only parentheses. So counter is enough.
But there is a twist: "bracket ratio" might refer to something else? I doubt.
Thus final code.
One more: The output expects "YES" or "NO" uppercase. So correct.
I will respond with the code only, no extra text. ```cpp
#include
#include
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int bal = 0;
bool ok = true;
for (char c : s) {
if (c == '(') {
bal++;
} else if (c == ')') {
if (bal == 0) {
ok = false;
break;
}
bal--;
}
}
if (ok && bal == 0) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}