Advertisement
Iskrenov84

09. Pokemon Don't Go

Feb 18th, 2022
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 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.             int sum = 0;
  19.  
  20.  
  21.             while (pokemonList.Count > 0)
  22.             {
  23.                 int input = int.Parse(Console.ReadLine());
  24.                
  25.                 if (input < 0)
  26.                 {
  27.                     int removeOne = pokemonList[0];
  28.                     //sumList.Add(pokemonList[pokemonList[0]]);
  29.                     pokemonList[0] = pokemonList[pokemonList.Count - 1];
  30.                     sum += removeOne;
  31.  
  32.                     LoopForIncreaseAndDecrease(pokemonList, removeOne);
  33.                 }
  34.  
  35.                 else if (input >= pokemonList.Count)
  36.                 {
  37.                     int removeTwo = pokemonList[pokemonList.Count - 1];
  38.                     //sumList.Add(pokemonList[pokemonList.Count - 1]);
  39.                     pokemonList[pokemonList.Count - 1] = pokemonList[0];
  40.                     sum += removeTwo;
  41.  
  42.                    LoopForIncreaseAndDecrease(pokemonList,removeTwo);
  43.                 }
  44.  
  45.                 else
  46.                 {
  47.                     int removeThree = pokemonList[input];
  48.                     //sumList.Add(pokemonList[input]);
  49.                     pokemonList.RemoveAt(input);
  50.                     sum += removeThree;
  51.  
  52.                     LoopForIncreaseAndDecrease(pokemonList,removeThree);                  
  53.                 }
  54.             }
  55.            
  56.             Console.WriteLine(sum);
  57.         }
  58.         static void LoopForIncreaseAndDecrease (List<int> pokemonList , int remove)
  59.         {
  60.             for (int i = 0; i < pokemonList.Count; i++)
  61.             {
  62.                 if (pokemonList[i] <= remove)
  63.                 {
  64.                     pokemonList[i] += remove;
  65.                 }
  66.                 else
  67.                 {
  68.                     pokemonList[i] -= remove;
  69.                 }
  70.             }
  71.         }
  72.     }
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement