Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- string input = string.Empty;
- List<int> myList = new List<int>();
- int lastElement = 0;
- do
- {
- input = Console.ReadLine();
- if (input != "bang" && input != "stop")
- {
- myList.Insert(0, int.Parse(input));
- }
- else if (input == "bang")
- {
- if (myList.Count > 0)
- {
- int sum = 0;
- for (int i = 0; i < myList.Count; i++)
- {
- sum += myList[i];
- }
- double average = sum / (double)myList.Count;
- for (int i = 0; i < myList.Count; i++)
- {
- if (myList[i] <= average)
- {
- lastElement = myList[i];
- myList.RemoveAt(i);
- Console.WriteLine($"shot {lastElement}");
- break;
- }
- }
- for (int i = 0; i < myList.Count; i++)
- {
- myList[i]--;
- }
- }
- else
- {
- Console.WriteLine($"nobody left to shoot! last one was {lastElement}");
- return;
- }
- }
- } while (input != "stop");
- if (myList.Count > 0)
- {
- Console.WriteLine($"survivors: " + string.Join(" ", myList));
- }
- else
- {
- Console.WriteLine($"you shot them all. last one was {lastElement}");
- }
Advertisement
Add Comment
Please, Sign In to add comment