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;
- using System.Threading.Tasks;
- class MoreExercises
- {
- static void Main()
- {
- var seqInt = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- var listToSum = new List<int>();
- var removedInt = 0;
- while (true)
- {
- int index = int.Parse(Console.ReadLine());
- if (index < 0)
- {
- removedInt = seqInt[0];
- listToSum.Add(removedInt);
- seqInt[0] = seqInt[seqInt.Count - 1];
- }
- else if (index > seqInt.Count - 1)
- {
- removedInt = seqInt[seqInt.Count - 1];
- listToSum.Add(removedInt);
- seqInt[seqInt.Count - 1] = seqInt[0];
- }
- else
- {
- removedInt = seqInt[index];
- listToSum.Add(removedInt);
- seqInt.RemoveAt(index);
- }
- for (int i = 0; i < seqInt.Count; i++)
- {
- if (seqInt[i] <= removedInt)
- {
- seqInt[i] = seqInt[i] + removedInt;
- }
- else if (seqInt[i] > removedInt)
- {
- seqInt[i] = seqInt[i] - removedInt;
- }
- }
- if (seqInt.Count == 0)
- {
- break;
- }
- }
- Console.WriteLine(listToSum.Sum());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement