Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- namespace Advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- var line = Console.ReadLine().Split();
- var stack = new Stack<string>(line);
- while (true)
- {
- var input = Console.ReadLine().ToLower();
- if (input == "end")
- {
- break;
- }
- var action = input.Split().ToArray();
- var command = action[0];
- if (command == "add")
- {
- var firstNumber = action[1];
- stack.Push(firstNumber);
- var secondNumber = action[2];
- stack.Push(secondNumber);
- }
- else if (command == "remove")
- {
- var numbersToRemove = int.Parse(action[1]);
- if (stack.Count >= numbersToRemove)
- {
- for (int i = 1; i <= numbersToRemove; i++)
- {
- stack.Pop();
- }
- }
- }
- }
- int sum = 0;
- foreach (var item in stack)
- {
- sum += int.Parse(item);
- }
- Console.WriteLine($"Sum: {sum}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement