Advertisement
valkata

Increasing Crisis

Jul 6th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 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 increasingCrisis
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int lists = int.Parse(Console.ReadLine());
  14.             List<int> finalList = new List<int>();
  15.  
  16.             for (int i = 0; i < lists; i++)
  17.             {
  18.                 List<int> temp = Console.ReadLine().Split().Select(int.Parse).ToList();
  19.                 if (i == 0)
  20.                 {
  21.                     finalList = temp;
  22.                 }
  23.                 else
  24.                 {
  25.                     CheckList(finalList, temp);
  26.                     CleanList(ref finalList);
  27.                 }
  28.  
  29.             }
  30.  
  31.             Console.WriteLine(string.Join(" ", finalList));
  32.         }
  33.  
  34.         static List<int> CheckList(List<int> finalList, List<int> temp)
  35.         {
  36.  
  37.             for (int i = 0; i < finalList.Count; i++)
  38.             {
  39.                 if(i == finalList.Count - 1 && finalList[i] <= temp[0])
  40.                 {
  41.                     finalList = AddList(finalList, temp, i);
  42.                     return finalList;
  43.                 }
  44.                 else if (finalList[i] <= temp[0] && finalList[i+1] > temp [0] )
  45.                 {
  46.                     finalList = AddList(finalList, temp, i);
  47.                     return finalList;
  48.                 }
  49.             }
  50.             return finalList;
  51.         }
  52.  
  53.         static List<int> AddList(List<int> finalList, List<int> temp, int number)
  54.         {
  55.             for (int i = 0; i < temp.Count; i++)
  56.             {
  57.                 finalList.Insert(number + i +1 , temp[i]);
  58.             }
  59.             return finalList;
  60.         }
  61.  
  62.         static List<int> CleanList(ref List<int> finalList)
  63.         {
  64.             List<int> newList = new List<int>();
  65.             for (int i = 0; i <= finalList.Count-1; i++)
  66.             {
  67.                 if(i == finalList.Count-1 && finalList[i]> finalList[i-1])
  68.                 {
  69.                     newList.Add(finalList[i]);
  70.                 }
  71.                 else if(finalList[i] > finalList[i + 1] )
  72.                 {
  73.                     newList.Add(finalList[i]);
  74.                     break;
  75.                 }
  76.                 else
  77.                 {
  78.                     newList.Add(finalList[i]);
  79.                 }
  80.             }
  81.             finalList = newList;
  82.             return finalList;
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement