static void Main(string[] args) { string[] firstInput = Console.ReadLine() .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries) .Skip(1) .ToArray(); MyStack <string> myStack = new MyStack <string>(firstInput); string commandData = Console.ReadLine(); while (commandData != "END") { string[] command = commandData.Split(); if (command[0] == "Push") { myStack.Push(command[1]); } else if (command[0] == "Pop") { myStack.Pop(); } commandData = Console.ReadLine(); } for (int i = 0; i < 2; i++) { foreach (var item in myStack) { Console.WriteLine(item); } } }
static void Main(string[] args) { MyStack <int> myStack = new MyStack <int>(); string commandInput = Console.ReadLine(); while (commandInput != "END") { string[] tokens = commandInput .Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries); string command = tokens[0]; if (command == "Push") { foreach (string item in tokens.Skip(1)) { myStack.Push(int.Parse(item)); } } else if (command == "Pop") { if (myStack.Count == 0) { Console.WriteLine("No elements"); } else { myStack.Pop(); } } commandInput = Console.ReadLine(); } foreach (int i in myStack) { Console.WriteLine(i); } foreach (int i in myStack) { Console.WriteLine(i); } }
static void Main(string[] args) { MyStack <int> myStack = new MyStack <int>(); string commandInput = Console.ReadLine(); while (commandInput != "END") { string[] commandData = commandInput.Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries); string command = commandData[0]; if (command == "Push") { for (int i = 1; i < commandData.Length; i++) { int item = int.Parse(commandData[i]); myStack.Push(item); } } else if (command == "Pop") { try { myStack.Pop(); } catch (InvalidOperationException ex) { Console.WriteLine(ex.Message); } } commandInput = Console.ReadLine(); } foreach (var item in myStack) { Console.WriteLine(item); } Console.WriteLine(string.Join(Environment.NewLine, myStack)); }
public static void Main() { string inputLine = String.Empty; var result = new MyStack <string>(); while ((inputLine = Console.ReadLine()) != "END") { var tokens = inputLine.Split(new[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries).ToList(); var command = tokens[0]; switch (command) { case "Push": foreach (var item in tokens.Skip(1)) { result.Push(item); } break; case "Pop": try { result.Pop(); } catch (Exception e) { Console.WriteLine(e.Message); } break; } } foreach (var res in result) { Console.WriteLine(res); } foreach (var res in result) { Console.WriteLine(res); } }
static void Main(string[] args) { MyStack <int> stack = new MyStack <int>(); string input; while ((input = Console.ReadLine()) != "END") { string[] tokens = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); string command = tokens[0]; switch (command) { case "Push": int[] items = tokens.Skip(1) .Select(int.Parse) .ToArray(); stack.Push(items); break; case "Pop": if (stack.Size == 0) { Console.WriteLine("No elements"); } else { stack.Pop(); } break; default: break; } } for (int i = 0; i < 2; i++) { Console.WriteLine(string.Join("\n", stack)); } }
static void Main(string[] args) { MyStack <int> myStack = new MyStack <int>(); string commandData = Console.ReadLine(); while (commandData != "END") { string[] commandArgs = commandData.Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries); string command = commandArgs[0]; if (command == "Push") { for (int i = 1; i < commandArgs.Length; i++) { int element = int.Parse(commandArgs[i]); myStack.Push(element); } } else if (command == "Pop") { myStack.Pop(); } commandData = Console.ReadLine(); } foreach (var element in myStack) { Console.WriteLine(element); } Console.WriteLine(string.Join(Environment.NewLine, myStack)); //Console.WriteLine(myStack.Pop()); //Console.WriteLine(myStack.Pop()); //Console.WriteLine(myStack.Pop()); //Console.WriteLine(myStack.Pop()); }