Advertisement
Filkolev

Pyramid

May 27th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. namespace Pyramid
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class Pyramid
  8.     {
  9.         public static void Main()
  10.         {
  11.             int countOfRows = int.Parse(Console.ReadLine());
  12.  
  13.             List<int> results = new List<int>();
  14.  
  15.             int min = int.Parse(Console.ReadLine().Trim());
  16.             results.Add(min);
  17.  
  18.             for (int row = 1; row < countOfRows; row++)
  19.             {
  20.                 var numbers = Console.ReadLine()
  21.                     .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  22.                     .Select(int.Parse);
  23.  
  24.                 try
  25.                 {
  26.                     min = numbers.Where(num => num > min).Min();
  27.                     results.Add(min);
  28.                 }
  29.                 catch (InvalidOperationException)
  30.                 {
  31.                     min++;
  32.                 }
  33.             }
  34.  
  35.             Console.WriteLine(string.Join(", ", results));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement