Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace RemoveOddOccurrences
  5. {
  6. public class RemoveOddOccurrences
  7. {
  8. public static void Main()
  9. {
  10. var input = Console.ReadLine().Split(new[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries)
  11. .Select(int.Parse).ToList();
  12.  
  13. input.Sort();
  14. input.Add(0);
  15.  
  16. int currCounter = 1;
  17. int currNumber = 0;
  18.  
  19. for (int i = 1; i < input.Count; i++)
  20. {
  21. currNumber = input[i - 1];
  22.  
  23. if (input[i] == input[i - 1])
  24. {
  25. currCounter++;
  26. }
  27. else
  28. {
  29. if (currCounter %2 == 1)
  30. {
  31. for (int k = i-currCounter; k <i ; k++)
  32. {
  33. input[k] = 0;
  34. }
  35. }
  36. currCounter = 1;
  37. }
  38. }
  39. input.RemoveAll(x => x == 0);
  40. Console.WriteLine(string.Join(" ", input));
  41.  
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement