Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 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 P03.Pokemon_Don_t_Go
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> sequence = Console.ReadLine()
  14. .Split(' ')
  15. .Select(int.Parse)
  16. .ToList();
  17.  
  18. int sum = 0;
  19. int removedElement = 0;
  20.  
  21. while (!sequence.Count.Equals(0))
  22. {
  23. int index = int.Parse(Console.ReadLine());
  24.  
  25. if (index < 0)
  26. {
  27. removedElement = sequence[0];
  28. sum += removedElement;
  29. sequence[0] = sequence[sequence.Count - 1];
  30.  
  31. IncreaseAndDecrease(sequence, removedElement);
  32. }
  33. else if (index >= sequence.Count)
  34. {
  35. removedElement = sequence[sequence.Count - 1];
  36. sum += removedElement;
  37. sequence[sequence.Count - 1] = sequence[0];
  38.  
  39. IncreaseAndDecrease(sequence, removedElement);
  40. }
  41. else
  42. {
  43. removedElement = sequence[index];
  44. sum += removedElement;
  45. sequence.RemoveAt(index);
  46.  
  47. IncreaseAndDecrease(sequence, removedElement);
  48. }
  49. }
  50.  
  51. Console.WriteLine(sum);
  52. }
  53.  
  54. private static List<int> IncreaseAndDecrease(List<int> sequence, int removedElement)
  55. {
  56. for (int i = 0; i < sequence.Count; i++)
  57. {
  58. if (sequence[i] <= removedElement)
  59. {
  60. sequence[i] += removedElement;
  61. }
  62. else if (sequence[i] > removedElement)
  63. {
  64. sequence[i] -= removedElement;
  65. }
  66. }
  67.  
  68. return sequence;
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement