Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace lookandsay
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] input = {1, 1, 6, 1, 3, 4, 2, 2};
  11.             int[] output = start(input);
  12.  
  13.             Console.ReadLine();
  14.         }
  15.  
  16.         private static int[] start(int[] inputs)
  17.         {
  18.             var queryResult = from x in inputs
  19.                     group x by x into g
  20.                     let count = g.Count()
  21.                     orderby g.Key descending
  22.                     select new { Value = g.Key, Count = count };
  23.  
  24.             var first = queryResult.First();
  25.  
  26.             int[] outputArray = new int[2];
  27.  
  28.             outputArray[0] = first.Count;
  29.             outputArray[1] = first.Value;
  30.            
  31.             foreach (var x in queryResult.Skip(1))
  32.             {
  33.                 outputArray = (new int[2]).Concat(outputArray).ToArray();
  34.                    
  35.                 outputArray[0] = x.Count;
  36.                 outputArray[1] = x.Value;
  37.             }
  38.  
  39.             return outputArray;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement