fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Test
  5. {
  6. public static List<int> odd(int[] InputList) {
  7. List<int> output = new List<int>();
  8. int start = 0;
  9. int pos = 1;
  10. while (pos < InputList.Length) {
  11. if (InputList[pos] != InputList[start]) {
  12. if ((pos-start) % 2 == 1) {
  13. output.Add(InputList[start]);
  14. }
  15. start = pos;
  16. }
  17. pos++;
  18. }
  19. // Process the last run
  20. if ((InputList.Length-start) % 2 == 1) {
  21. output.Add(InputList[start]);
  22. }
  23. return output;
  24. }
  25. public static void Main()
  26. {
  27. List<int> res = odd(new[] {2,2,3,3,3,4,4,5,5,5,5,5});
  28. for (int i = 0 ; i != res.Count ; i++) {
  29. Console.WriteLine(res[i]);
  30. }
  31. }
  32. }
Success #stdin #stdout 0.03s 24192KB
stdin
Standard input is empty
stdout
3
5