Advertisement
Rayk

Untitled

Nov 2nd, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class MoreExercises
  8. {
  9. static void Main()
  10. {
  11. var seqInt = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  12. var listToSum = new List<int>();
  13. var removedInt = 0;
  14. while (true)
  15. {
  16. int index = int.Parse(Console.ReadLine());
  17. if (index < 0)
  18. {
  19. removedInt = seqInt[0];
  20. listToSum.Add(removedInt);
  21. seqInt[0] = seqInt[seqInt.Count - 1];
  22. }
  23. else if (index > seqInt.Count - 1)
  24. {
  25. removedInt = seqInt[seqInt.Count - 1];
  26. listToSum.Add(removedInt);
  27. seqInt[seqInt.Count - 1] = seqInt[0];
  28. }
  29. else
  30. {
  31. removedInt = seqInt[index];
  32. listToSum.Add(removedInt);
  33. seqInt.RemoveAt(index);
  34. }
  35.  
  36. for (int i = 0; i < seqInt.Count; i++)
  37. {
  38. if (seqInt[i] <= removedInt)
  39. {
  40. seqInt[i] = seqInt[i] + removedInt;
  41. }
  42. else if (seqInt[i] > removedInt)
  43. {
  44. seqInt[i] = seqInt[i] - removedInt;
  45. }
  46. }
  47. if (seqInt.Count == 0)
  48. {
  49. break;
  50. }
  51. }
  52. Console.WriteLine(listToSum.Sum());
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement