Advertisement
Iskrenov84

09. Pokemon Don't Go

Feb 18th, 2022
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace L9._PokemonDon_tGo
  7. {
  8.     internal class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<int>  pokemonList = Console.ReadLine()
  13.                 .Split(' ',StringSplitOptions.RemoveEmptyEntries)
  14.                 .Select(int.Parse)
  15.                 .ToList();
  16.  
  17.             List<int> sumList = new List<int>();
  18.  
  19.  
  20.             while (pokemonList.Count > 0)
  21.             {
  22.                 int input = int.Parse(Console.ReadLine());
  23.                
  24.                 if (input < 0)
  25.                 {
  26.                     int removeOne = pokemonList[0];
  27.                     sumList.Add(pokemonList[pokemonList[0]]);
  28.                     pokemonList[0] = pokemonList[pokemonList.Count - 1];
  29.  
  30.                     LoopForIncreaseAndDecrease(pokemonList, removeOne);
  31.                 }
  32.  
  33.                 else if (input >= pokemonList.Count)
  34.                 {
  35.                     int removeTwo = pokemonList[pokemonList.Count - 1];
  36.                     sumList.Add(pokemonList[pokemonList.Count - 1]);
  37.                     pokemonList[pokemonList.Count - 1] = pokemonList[0];
  38.  
  39.                    LoopForIncreaseAndDecrease(pokemonList,removeTwo);
  40.                 }
  41.  
  42.                 else
  43.                 {
  44.                     int removeThree = pokemonList[input];
  45.                     sumList.Add(pokemonList[input]);
  46.                     pokemonList.RemoveAt(input);
  47.  
  48.                     LoopForIncreaseAndDecrease(pokemonList,removeThree);                  
  49.                 }
  50.             }
  51.            
  52.             Console.WriteLine(sumList.Sum());
  53.         }
  54.         static void LoopForIncreaseAndDecrease (List<int> pokemonList , int remove)
  55.         {
  56.             for (int i = 0; i < pokemonList.Count; i++)
  57.             {
  58.                 if (pokemonList[i] <= remove)
  59.                 {
  60.                     pokemonList[i] += remove;
  61.                 }
  62.                 else
  63.                 {
  64.                     pokemonList[i] -= remove;
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement