Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Lists10_Grains_of_sand
- {
- class Program
- {
- static void Main()
- {
- List<int> sands = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToList();
- string input = Console.ReadLine();
- while (input != "Mort")
- {
- string[] tokens = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string command = tokens[0];
- int value = int.Parse(tokens[1]);
- switch (command)
- {
- case "Add":
- sands.Add(value);
- break;
- case "Remove":
- if (sands.Contains(value))
- {
- sands.Remove(value);
- }
- else if (value >= 0 && value < sands.Count)
- {
- sands.RemoveAt(value);
- }
- break;
- case "Replace":
- int replacement = int.Parse(tokens[2]);
- if (sands.Contains(value))
- {
- int indexToreplace = sands.IndexOf(value);
- sands[indexToreplace] = replacement;
- }
- break;
- case "Increase":
- if (sands.Exists(x => x >= value))
- {
- sands = sands.Select(x => x + value).ToList();
- }
- else
- {
- sands = sands.Select(x => x + sands[sands.Count - 1]).ToList();
- }
- break;
- case "Collapse":
- sands.RemoveAll(x => x < value);
- break;
- }
- input = Console.ReadLine();
- }
- Console.WriteLine(string.Join(" ", sands));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement