WindFell

Pokemons Don't Go

Jun 20th, 2018
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class PokemonDontGo
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         List<int> pokemons = Console.ReadLine()
  10.             .Split()
  11.             .Select(int.Parse)
  12.             .ToList();
  13.  
  14.         int sum = 0;
  15.  
  16.         while (pokemons.Count > 0)
  17.         {
  18.             int index = int.Parse(Console.ReadLine());
  19.  
  20.             int lastIndex = pokemons.Count - 1;
  21.             int pokemon = 0;
  22.  
  23.             if (index < 0)
  24.             {
  25.                 pokemon = pokemons[0];
  26.                 pokemons[0] = pokemons[lastIndex];
  27.             }
  28.             else if (index > lastIndex)
  29.             {
  30.                 pokemon = pokemons[lastIndex];
  31.                 pokemons[lastIndex] = pokemons[0];
  32.             }
  33.             else
  34.             {
  35.                 pokemon = pokemons[index];
  36.                 pokemons.RemoveAt(index);
  37.             }
  38.  
  39.             sum += pokemon;
  40.  
  41.             for (int currentIndex = 0; currentIndex < pokemons.Count; currentIndex++)
  42.             {
  43.                 if (pokemons[currentIndex] <= pokemon)
  44.                 {
  45.                     pokemons[currentIndex] += pokemon;
  46.                 }
  47.                 else
  48.                 {
  49.                     pokemons[currentIndex] -= pokemon;
  50.                 }
  51.             }
  52.         }
  53.  
  54.         Console.WriteLine(sum);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment