Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You are a given pyramid of integer numbers. Your task is to print a growing sequence of integers, starting from the top of the pyramid.
- * If a row does not contain a number larger than the previous one, we go to the next row and search for a number greater than the previous number + 1.
- * On the first line, you will get the number of lines N. On the next N you will get the rows of the pyramid. The numbers in each row are separated by one or more spaces. There will be a different number of spaces at the beginning of each line. */
- namespace Pyramid
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Pyramid
- {
- static void Main(string[] args)
- {
- int count = int.Parse(Console.ReadLine());
- List<int> growingList = new List<int>();
- int maxNum = int.MinValue;
- for (int i = 0; i < count; i++)
- {
- int[] nums =
- Console.ReadLine()
- .Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- Array.Sort(nums);
- bool isFoundLarger = false;
- for (int j = 0; j < nums.Length; j++)
- {
- if (nums[j] > maxNum)
- {
- maxNum = nums[j];
- isFoundLarger = true;
- growingList.Add(maxNum);
- break;
- }
- }
- if (!isFoundLarger)
- {
- maxNum++;
- }
- }
- Console.WriteLine(string.Join(", ", growingList));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement