Advertisement
grubcho

Shoot list elements

Jun 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 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 Shoot_list_elements
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> list = new List<int>();
  14.             bool stop = false;
  15.             int lastOne = 0;
  16.             while (!stop)
  17.             {
  18.                 string command = Console.ReadLine();                
  19.                 if (command == "stop")
  20.                 {
  21.                     if (list.Count > 0)
  22.                     {
  23.                         Console.WriteLine("survivors: " + string.Join(" ", list));
  24.                     }
  25.                     else if (list.Count == 0)
  26.                     {
  27.                         Console.WriteLine($"you shot them all. last one was {lastOne}");
  28.                     }
  29.                     stop = true;
  30.                 }
  31.                 else if (command == "bang")
  32.                 {
  33.                    
  34.                     if (list.Count == 0)
  35.                     {
  36.                         Console.WriteLine($"nobody left to shoot! last one was {lastOne}");
  37.                         stop = true;                        
  38.                     }
  39.                     else
  40.                     {
  41.                         for (int i = 0; i < list.Count; i++)
  42.                         {
  43.                             if (list[i] <= list.Average())
  44.                             {
  45.                                 Console.WriteLine($"shot {list[i]}");
  46.                                 lastOne = list[i];
  47.                                 list.Remove(list[i]);
  48.                                 list = list.Select(e => e - 1).ToList();
  49.                                 break;
  50.                             }
  51.                         }
  52.                     }                                        
  53.                     //Console.WriteLine(string.Join(" ", list));
  54.                 }
  55.                 else
  56.                 {
  57.                     int elementToInsert = int.Parse(command);
  58.                     list.Insert(0, elementToInsert);            
  59.                 }
  60.             }            
  61.         }      
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement