fork(3) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var data = new int[] { 4, 1, 1, 3, 3, 2, 5, 3, 2, 2 };
  11. var result = data.Select ((item, index) =>
  12. new
  13. {
  14. Key = item,
  15. Count = (index == 0 || data.ElementAt(index - 1) != item)
  16. ? data.Skip(index).TakeWhile (d => d == item).Count ()
  17. : -1
  18. }
  19. )
  20. .Where (d => d.Count != -1);
  21.  
  22. foreach(var item in result)
  23. {
  24. Console.WriteLine(string.Format("{0} => {1}", item.Key, item.Count));
  25. }
  26. }
  27. }
Success #stdin #stdout 0.03s 37144KB
stdin
Standard input is empty
stdout
4 => 1
1 => 2
3 => 2
2 => 1
5 => 1
3 => 1
2 => 2