Advertisement
NelIfandieva

PrFund_Exam_09July2017_Problem02

Mar 1st, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6.  
  7. namespace PokemonDontGo_Exam_09July2017
  8. {
  9.     class MainClass
  10.     {
  11.         /* */
  12.  
  13.         public static void Main()
  14.         {
  15.             char[] sepSpace = { ' ' };
  16.             var input = Console.ReadLine()
  17.                               .Split(sepSpace, StringSplitOptions.RemoveEmptyEntries)
  18.                                .Select(long.Parse)
  19.                                .ToList();
  20.             var inputCopy = new List<long>();
  21.  
  22.             for (int a = 0; a < input.Count; a++)
  23.             {
  24.                 inputCopy.Add(input[a]);
  25.             }
  26.             long valueOfRemoved = 0;
  27.             long valueExchange = 0;
  28.             var listOfRemoved = new List<long>();
  29.             while(inputCopy.Count > 0)
  30.             {
  31.                 int index = int.Parse(Console.ReadLine());
  32.                 if(index >= 0 && index <= inputCopy.Count - 1)//return <=, necessary if
  33.                 {
  34.                     valueOfRemoved = input[index];
  35.                     listOfRemoved.Add(valueOfRemoved);
  36.                     inputCopy.RemoveAt(index);
  37.                     for (int i = 0; i < inputCopy.Count; i++)
  38.                     {
  39.                         if(inputCopy[i] <= valueOfRemoved)
  40.                         {
  41.                             inputCopy[i] += valueOfRemoved;
  42.                         }
  43.                         else
  44.                         {
  45.                             inputCopy[i] -= valueOfRemoved;
  46.                         }
  47.                     }
  48.                 }
  49.                 else if(index < 0)
  50.                 {
  51.                     valueOfRemoved = inputCopy[0];
  52.                     listOfRemoved.Add(valueOfRemoved);
  53.                     valueExchange = inputCopy[inputCopy.Count - 1];
  54.                     inputCopy[0] = valueExchange;
  55.                     for (int z = 0; z < inputCopy.Count; z++)
  56.                     {
  57.                         if(inputCopy[z] <= valueOfRemoved)
  58.                         {
  59.                             inputCopy[z] += valueOfRemoved;
  60.                         }
  61.                         else
  62.                         {
  63.                             inputCopy[z] -= valueOfRemoved;
  64.                         }
  65.                     }
  66.                 }
  67.                 else
  68.                 {
  69.                     valueOfRemoved = inputCopy[inputCopy.Count - 1];
  70.                     listOfRemoved.Add(valueOfRemoved);
  71.                     valueExchange = inputCopy[0];
  72.                     inputCopy[inputCopy.Count - 1] = valueExchange;
  73.                     for (int f = 0; f < inputCopy.Count; f++)
  74.                     {
  75.                         if(inputCopy[f] <= valueOfRemoved)
  76.                         {
  77.                             inputCopy[f] += valueOfRemoved;
  78.                         }
  79.                         else
  80.                         {
  81.                             inputCopy[f] -= valueOfRemoved;
  82.                         }
  83.                     }
  84.                 }
  85.             }
  86.             Console.Write(listOfRemoved.Sum());
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement