Advertisement
grubcho

Camel's back - Lists

Jun 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 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. //The city is breaking down on a camel back. You will receive a sequence of N integers, (space-separated), which will represent the //buildings in the city.  You will then receive an integer M, indicating the camel back's size.
  7. //The camel back is a linear structure standing below the city, in such a way that it has an equal amount of buildings to its left and //right. The idea is, if every round – one building falls from the left side of the city, and one from the right side, how many rounds //will it take for the city to stop breaking down?
  8. //As output you must print how many rounds it took before the city stopped breaking down as “{rounds} rounds”. On the next line, print //what’s left of the city (space-separated). Format: “remaining: {buildings (space-separated)}”
  9. //If no buildings have fallen, print “already stable: {buildings (space-separated)}”
  10.  
  11. namespace camel_s_back
  12. {
  13.     class Program
  14.     {
  15.         static void Main(string[] args)
  16.         {
  17.             List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  18.             int backCount = int.Parse(Console.ReadLine());
  19.             int rounds = (input.Count - backCount) / 2;
  20.             if (input.Count > backCount)
  21.             {
  22.                 for (int i = 0; i < rounds; i++)
  23.                 {
  24.                     input.RemoveAt(0);
  25.                     input.RemoveAt(input.Count - 1);
  26.                 }
  27.                 Console.WriteLine($"{rounds} rounds");
  28.                 Console.WriteLine("remaining: " + string.Join(" ", input));
  29.             }
  30.             else
  31.             {
  32.                 Console.WriteLine("already stable: " + string.Join(" ", input));
  33.             }
  34.            
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement