Advertisement
dobroslav_atanasov

IncreasingCrisis

Mar 1st, 2017
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.IncreasingCrisis
  6. {
  7.     public class IncreasingCrisis
  8.     {
  9.         public static void Main()
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.  
  13.             var list = new List<int>();
  14.  
  15.             for (int i = 1; i <= n; i++)
  16.             {
  17.                 var sequence = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  18.                 int rightMostElement = 0;
  19.                 int position = 0;
  20.                 bool isBreak = false;
  21.  
  22.                 if (list.Count == 0)
  23.                 {
  24.                     for (int j = 0; j < sequence.Count; j++)
  25.                     {
  26.                         list.Add(sequence[j]);
  27.                     }
  28.                 }
  29.                 else
  30.                 {
  31.                     for (int j = 0; j < sequence.Count; j++)
  32.                     {
  33.                         for (int k = 0; k < list.Count; k++)
  34.                         {
  35.                             if (sequence[j] > list[k])
  36.                             {
  37.                                 rightMostElement = list[k];
  38.                                 position = list.IndexOf(rightMostElement);
  39.                             }
  40.                             else if (sequence[j] == list[k])
  41.                             {
  42.                                 position++;
  43.                             }
  44.                         }
  45.                         break;
  46.                     }
  47.  
  48.                     list.InsertRange(position + 1, sequence);
  49.                 }
  50.  
  51.                 int breakElement = 0;
  52.                 int breakPostion = 0;
  53.  
  54.                 for (int j = 1; j < list.Count; j++)
  55.                 {
  56.                     if (list[j] < list[j - 1])
  57.                     {
  58.                         breakElement = list[j];
  59.                         breakPostion = list.LastIndexOf(breakElement);
  60.                         isBreak = true;
  61.                         break;
  62.                     }
  63.                 }
  64.  
  65.                 if (isBreak)
  66.                 {
  67.                     for (int j = list.Count - 1; j >= breakPostion; j--)
  68.                     {
  69.                         list.RemoveAt(j);
  70.                     }
  71.                 }
  72.             }
  73.  
  74.             Console.WriteLine(string.Join(" ", list));
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement