Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Socks
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int[] leftSockSequance = Console.ReadLine()
  13. .Split()
  14. .Select(int.Parse)
  15. .ToArray();
  16.  
  17. int[] rightSockSequance = Console.ReadLine()
  18. .Split()
  19. .Select(int.Parse)
  20. .ToArray();
  21.  
  22. Stack<int> leftSocks = new Stack<int>(leftSockSequance);
  23. Queue<int> rightSocks = new Queue<int>(rightSockSequance);
  24. List<int> pairs = new List<int>();
  25.  
  26.  
  27. for (int i = 0; i < rightSockSequance.Length; i++)
  28. {
  29. int currentLeftSock = leftSocks.Peek();
  30. int currentRighttSock = rightSocks.Peek();
  31.  
  32. if (currentLeftSock > currentRighttSock)
  33. {
  34. int pair = currentRighttSock + currentLeftSock;
  35. pairs.Add(pair);
  36. leftSocks.Pop();
  37. rightSocks.Dequeue();
  38. }
  39. else if (currentRighttSock > currentLeftSock)
  40. {
  41. leftSocks.Pop();
  42. }
  43. else if (currentLeftSock == currentRighttSock)
  44. {
  45. rightSocks.Dequeue();
  46. leftSocks.Pop();
  47. leftSocks.Push(currentLeftSock + 1);
  48. }
  49. }
  50.  
  51. Console.WriteLine(pairs.Max());
  52.  
  53. foreach (var pair in pairs)
  54. {
  55. Console.Write(pair + " ");
  56. }
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement