Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace HomeWork1
  5. {
  6.     public class Program
  7.     {
  8.         public static void Main(string[] args)
  9.  
  10.         {
  11.             string inp = Console.ReadLine();
  12.             bool result = false;
  13.             if (inp != null)
  14.             {
  15.                 char[] myInp = inp.ToCharArray();
  16.  
  17.                 //Stack<int> resultStack = new Stack<int>();
  18.                 List<int> resultArr = new List<int>();
  19.                 bool forceStop = false;
  20.                 for (int i = 0; i < myInp.Length; i++)
  21.                 {
  22.                     char temp = myInp[i];
  23.  
  24.  
  25.                     if (temp == '(')
  26.                     {
  27.                         //resultStack.Push(1);
  28.                         resultArr.Add(1);
  29.                         Console.Write(" +");
  30.                     }
  31.                     else if (temp == ')')
  32.                     {
  33.                         if (resultArr.Count > 0)//resultStack.Count > 0)
  34.                         {
  35.                             //int k = resultStack.Pop();
  36.                             resultArr.RemoveAt(resultArr.Count-1);
  37.                             Console.Write(" -");
  38.                             }
  39.                         else
  40.                         {
  41.                             forceStop = true;
  42.                             break;
  43.                         }
  44.                     }
  45.                 }
  46.                 if (resultArr.Count == 0 && !forceStop) //resultStack.Count == 0)
  47.                 {
  48.                     result = true;
  49.                 }
  50.             }
  51.             Console.WriteLine();
  52.             Console.WriteLine(result.ToString());
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement