Advertisement
Aborigenius

Pyramidic

Aug 23rd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 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 Pyramidic
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             List<string> lines = new List<string>();
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.                 lines.Add(Console.ReadLine());
  18.             }
  19.             List<string> allPyramids = new List<string>();
  20.             for (int i = 0; i < lines.Count; i++)
  21.             {
  22.                 string line = lines[i];
  23.                 for (int j = 0; j < line.Length; j++)
  24.                 {
  25.                     char @char = line[j];
  26.                     string pyramid = FindPyramid(@char, lines, i);
  27.                     allPyramids.Add(pyramid);
  28.                 }
  29.             }
  30.             string biggst = allPyramids.OrderByDescending(p => p.Length).First();
  31.             Console.WriteLine(biggst);
  32.         }
  33.  
  34.         private static string FindPyramid(char @char, List<string> lines, int linenumber)
  35.         {
  36.             int count = 3;
  37.             string pyramid = "" + @char + "\r\n";
  38.             for (int i = linenumber +1; i < lines.Count; i++)
  39.             {
  40.                 string toFind = new string(@char, count);
  41.  
  42.                 if (lines[i].Contains(toFind))
  43.                 {
  44.                     pyramid += toFind + "\r\n";
  45.                     count += 2;
  46.                 }
  47.                 else
  48.                 {
  49.                     return pyramid;
  50.                 }
  51.             }
  52.             return pyramid;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement