Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- string[] arrBraces = Console.ReadLine().Split(' ');
- string[] result = new String[arrBraces.Length];
- for (int i = 0; i < arrBraces.Length; i++) {
- Console.WriteLine(arrBraces[i]);
- int curly = 0, square = 0, round = 0;
- foreach (char c in arrBraces[i]) {
- if (c == '{') {
- curly++;
- } else if (c == '[') {
- square++;
- } else if (c == '(') {
- round++;
- } else if (c == '}') {
- if (curly > 0) {
- curly--;
- } else {
- curly = -1;
- break;
- }
- } else if (c == ']') {
- if (square > 0) {
- square--;
- } else {
- square = -1;
- break;
- }
- } else if (c == ')') {
- if (round > 0) {
- round--;
- } else {
- round = -1;
- break;
- }
- }
- }
- if (curly == 0 && square == 0 && round == 0) {
- result[i] = "YES";
- } else {
- result[i] = "NO";
- }
- }
- foreach (string str in result) {
- Console.WriteLine (str);
- }
- Console.ReadKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement