Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Brackets
- {
- static void Main()
- {
- string expr = ")((2+3)/2)(";
- CheckIsTheExpresionIsCorrect(expr);
- }
- static void CheckIsTheExpresionIsCorrect(string expr)
- {
- char[] exprCharArr = expr.ToCharArray();
- int bracket = 0;
- bool res = true;
- for (int i = 0; i < exprCharArr.Length; i++)
- {
- if (exprCharArr[i] == '(')
- {
- bracket++;
- }
- else if (exprCharArr[i] == ')')
- {
- bracket--;
- }
- if (bracket<0)
- {
- break;
- }
- }
- if (bracket == 0)
- {
- Console.WriteLine("The expresion is correct!");
- }
- else
- {
- Console.WriteLine("The expresion is NOT correct!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement