Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Numerics;
- namespace Exam_Pr02
- {
- class Program
- {
- static void Main()
- {
- List<BigInteger> initial = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(BigInteger.Parse).ToList();
- while(true)
- {
- var line = Console.ReadLine();
- if(line == "Mort")
- {
- break;
- }
- string[] commands = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string command = commands[0];
- int value = int.Parse(commands[1]);//maybe long
- if(command == "Add")
- {
- initial.Add(value);
- }
- else if(command == "Remove")
- {
- if(initial.Contains(value))
- {
- initial.Remove(value);
- }
- else
- {
- if(value >= 0 && value < initial.Count)
- {
- initial.RemoveAt(value); //double-check
- }
- }
- }
- else if (command == "Replace")
- {
- int replacement = int.Parse(commands[2]);
- if(initial.Contains(value))
- {
- int indexOfValue = initial.IndexOf(value);
- initial.RemoveAt(indexOfValue);
- initial.Insert(indexOfValue, replacement); // double-check
- }
- }
- else if (command == "Increase")
- {
- int indexFirstGreaterOrEqualToValue = initial.FindIndex(x => x >= value);//check
- BigInteger increaseValue = 0;
- if (indexFirstGreaterOrEqualToValue > -1)
- {
- increaseValue = initial[indexFirstGreaterOrEqualToValue];
- for (int a = 0; a < initial.Count; a++)
- {
- initial[a] += increaseValue;//check uslovieto
- }
- }
- else
- {
- increaseValue = initial[initial.Count - 1];
- for (int a = 0; a < initial.Count; a++)
- {
- initial[a] += increaseValue;//check uslovieto
- }
- }
- }
- else if (command == "Collapse")
- {
- for(int a = 0; a < initial.Count; a++)
- {
- if(initial[a] < value)
- {
- initial.Remove(initial[a]);
- a--;
- }
- }
- }
- }
- Console.Write(string.Join(" ", initial));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement