Advertisement
NelIfandieva

ProgFund_Exam_27Aug2018_Pr02_GrainsOfSands

Oct 27th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5. using System.Numerics;
  6.  
  7. namespace Exam_Pr02
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             List<BigInteger> initial = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(BigInteger.Parse).ToList();
  14.  
  15.             while(true)
  16.             {
  17.                 var line = Console.ReadLine();
  18.                 if(line == "Mort")
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 string[] commands = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  24.                 string command = commands[0];
  25.                 int value = int.Parse(commands[1]);//maybe long
  26.                 if(command == "Add")
  27.                 {
  28.                     initial.Add(value);
  29.                 }
  30.                 else if(command == "Remove")
  31.                 {
  32.                     if(initial.Contains(value))
  33.                     {
  34.                         initial.Remove(value);
  35.                     }
  36.                     else
  37.                     {
  38.                         if(value >= 0 && value < initial.Count)
  39.                         {
  40.                             initial.RemoveAt(value); //double-check
  41.                         }
  42.                     }
  43.                 }
  44.                 else if (command == "Replace")
  45.                 {
  46.                     int replacement = int.Parse(commands[2]);
  47.                     if(initial.Contains(value))
  48.                     {
  49.                         int indexOfValue = initial.IndexOf(value);
  50.                         initial.RemoveAt(indexOfValue);
  51.                         initial.Insert(indexOfValue, replacement); // double-check
  52.                     }
  53.                 }
  54.                 else if (command == "Increase")
  55.                 {
  56.                     int indexFirstGreaterOrEqualToValue = initial.FindIndex(x => x >= value);//check
  57.                     BigInteger increaseValue = 0;
  58.                     if (indexFirstGreaterOrEqualToValue > -1)
  59.                     {
  60.                         increaseValue = initial[indexFirstGreaterOrEqualToValue];
  61.                        
  62.                         for (int a = 0; a < initial.Count; a++)
  63.                         {
  64.                             initial[a] += increaseValue;//check uslovieto
  65.                         }
  66.                     }
  67.                     else
  68.                     {
  69.                         increaseValue = initial[initial.Count - 1];
  70.                        
  71.                         for (int a = 0; a < initial.Count; a++)
  72.                         {
  73.                             initial[a] += increaseValue;//check uslovieto
  74.                         }
  75.                     }
  76.                 }
  77.                 else if (command == "Collapse")
  78.                 {
  79.                     for(int a = 0; a < initial.Count; a++)
  80.                     {
  81.                         if(initial[a] < value)
  82.                         {
  83.                             initial.Remove(initial[a]);
  84.                             a--;
  85.                         }
  86.                     }
  87.                 }
  88.             }
  89.             Console.Write(string.Join(" ", initial));
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement