Neat Brackets
Limits
1s, 512 MB
Given a sequence of opening and closing parentheses (“(” and “)”) you will have to determine if it is a valid one.
A sequence of parentheses is considered valid if every opened parenthesis has a closing parenthesis appearing after it. And, there are no unpaired parenthesis in the sequence.
A sequence of parentheses is considered valid if every opened parenthesis has a closing parenthesis appearing after it. And, there are no unpaired parenthesis in the sequence.
Input
The input will contain a string of opening and closing parentheses. The string will be no longer than 25 characters.
Output
Print “Yes” if the input string contains a valid sequence of parentheses. Otherwise, print “No”.
#include<stdio.h>
#include<string.h>
int main()
{
char s[30];
int i,a=0,b=0;
gets(s);
for(i=0; i<strlen(s); i++)
{
if(s[i]=='(')
a++;
if(s[i]==')')
b++;
}
if(s[0]==')')
printf("No\n");
else if(a==b)
printf("Yes\n");
else
printf("No\n");
return 0;
}