Magical String II
Magical Girl Emily uses "magical strings" to cast spells. For her, a string X is magical if and only there are no consecutive '(' or ')' characters . The string is invalid if it contains any character other than '(' and ')'.
Given a string, write a program to find whether it is magical or not.
Input and Output Format:
Input consists of a string. Assume that the maximum length of the string is 100.
Output 'invalid' if the string is invalid. Output 'yes' if the string is magical or 'no' if the string is not magical.
Sample Input 1:
()()(
Sample Output 1:
yes
Sample Input 2:
(()()
Sample Output 2:
no
Sample Input 3:
(((&))
Sample Output 3:
invalid
10 | if(a[i]!='(' && a[i]!=')') |
No comments: