Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace lookandsay
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] input = {1, 1, 6, 1, 3, 4, 2, 2};
- int[] output = start(input);
- Console.ReadLine();
- }
- private static int[] start(int[] inputs)
- {
- var queryResult = from x in inputs
- group x by x into g
- let count = g.Count()
- orderby g.Key descending
- select new { Value = g.Key, Count = count };
- var first = queryResult.First();
- int[] outputArray = new int[2];
- outputArray[0] = first.Count;
- outputArray[1] = first.Value;
- foreach (var x in queryResult.Skip(1))
- {
- outputArray = (new int[2]).Concat(outputArray).ToArray();
- outputArray[0] = x.Count;
- outputArray[1] = x.Value;
- }
- return outputArray;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement