Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
- string[] command = Console.ReadLine().ToLower().Split().ToArray();
- Stack<int> stack = new Stack<int>(numbers);
- while (command[0] != "end")
- {
- if (command[0].ToLower() == "add")
- {
- int number1 = int.Parse(command[1]);
- int number2 = int.Parse(command[2]);
- stack.Push(number1);
- stack.Push(number2);
- }
- if (command[0] == "remove")
- {
- int count = int.Parse(command[1]);
- if (stack.Count > count)
- {
- for (int i = 0; i < count; i++)
- {
- stack.Pop();
- }
- }
- }
- command = Console.ReadLine().ToLower().Split().ToArray();
- }
- Console.WriteLine($"Sum: {stack.Sum()}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement