Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2017
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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. namespace ExamPrepJuly
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var myList = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.  
  15. int valueKeeper = 0;
  16. while (myList.Count>0)
  17. {
  18. int index = int.Parse(Console.ReadLine());
  19. int value = 0;
  20. if (index<0)
  21. {
  22. //here we get the value of the index that we want to remove
  23. value = myList[0];
  24. myList[0] = myList[myList.Count - 1];
  25. valueKeeper += value;
  26. }
  27. else if (index>myList.Count-1)
  28. {
  29. //here we get the value of the index that we want to remove
  30. value = myList[myList.Count - 1];
  31. myList[myList.Count - 1] = myList[0];
  32. valueKeeper += value;
  33. }
  34. else
  35. {
  36. //here we get the value of the index that we want to remove
  37. value = myList.ElementAt(index);
  38. myList.RemoveAt(index);
  39. valueKeeper += value;
  40. }
  41.  
  42. for (int i = 0; i < myList.Count; i++)
  43. {
  44. if (myList[i]<=value)
  45. {
  46. myList[i] += value;
  47. }
  48. else if (myList[i]>value)
  49. {
  50. myList[i] -= value;
  51. }
  52. }
  53.  
  54. }
  55.  
  56.  
  57. Console.WriteLine(valueKeeper);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement