Advertisement
Danny_Berova

05.Increasing Crisis

Jun 30th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1.  
  2. namespace _05.IncreasingCrisis
  3. {
  4.     using System;
  5.     using System.Collections.Generic;
  6.     using System.Linq;
  7.  
  8.     public class Program
  9.     {
  10.         static List<int> sequence = new List<int>();
  11.         public static void Main()
  12.         {
  13.             int numOfLines = int.Parse(Console.ReadLine());
  14.             List<int> sequence = new List<int>(0);
  15.  
  16.             for (int i = 0; i < numOfLines; i++)
  17.             {
  18.                 List<int> currentSequence = Console.ReadLine()
  19.                     .Split(new [] { (' ') }, StringSplitOptions.RemoveEmptyEntries)
  20.                     .Select(int.Parse).ToList();
  21.                 int index = 0;
  22.  
  23.                 if (sequence.Count == 0)
  24.                 {
  25.                     sequence.AddRange(currentSequence);
  26.                 }
  27.                 else
  28.                 {
  29.                     for (int find = 0; find < sequence.Count; find++)
  30.                     {
  31.                         if (sequence[find] <= currentSequence[0])
  32.                         {
  33.                             index++;
  34.                         }
  35.                         else
  36.                         {
  37.                             break;
  38.                         }
  39.                     }
  40.                     sequence.InsertRange(index, currentSequence);
  41.                     index = 0;
  42.                     bool isBroken = false;
  43.  
  44.                     for (int broken = 1; broken < sequence.Count; broken++)
  45.                     {
  46.                         if (sequence[broken - 1] > sequence[broken])
  47.                         {
  48.                             isBroken = true;
  49.                             index = broken;
  50.                             break;
  51.                         }
  52.                     }
  53.  
  54.                     if (isBroken)
  55.                     {
  56.                         sequence.RemoveRange(index, sequence.Count - index);
  57.                     }
  58.                 }
  59.             }
  60.  
  61.             Console.WriteLine(string.Join(" ", sequence));
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement