Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace HomeWork1
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- string inp = Console.ReadLine();
- bool result = false;
- if (inp != null)
- {
- char[] myInp = inp.ToCharArray();
- //Stack<int> resultStack = new Stack<int>();
- List<int> resultArr = new List<int>();
- bool forceStop = false;
- for (int i = 0; i < myInp.Length; i++)
- {
- char temp = myInp[i];
- if (temp == '(')
- {
- //resultStack.Push(1);
- resultArr.Add(1);
- Console.Write(" +");
- }
- else if (temp == ')')
- {
- if (resultArr.Count > 0)//resultStack.Count > 0)
- {
- //int k = resultStack.Pop();
- resultArr.RemoveAt(resultArr.Count-1);
- Console.Write(" -");
- }
- else
- {
- forceStop = true;
- break;
- }
- }
- }
- if (resultArr.Count == 0 && !forceStop) //resultStack.Count == 0)
- {
- result = true;
- }
- }
- Console.WriteLine();
- Console.WriteLine(result.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement