Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Exam27OctProblem1
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> males = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  12.             List<int> females = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  13.  
  14.             males = RefineMatches(males);
  15.             females = RefineMatches(females);
  16.  
  17.             Stack<int> maleCandidates = new Stack<int>(males);
  18.             Queue<int> femaleCandidates = new Queue<int>(females);
  19.  
  20.             int matches = 0;
  21.  
  22.             while (femaleCandidates.Count != 0 && maleCandidates.Count != 0)
  23.             {
  24.                 int girl = femaleCandidates.Peek();
  25.                 int guy = maleCandidates.Peek();
  26.  
  27.                 if (girl == guy)
  28.                 {
  29.                     femaleCandidates.Dequeue();
  30.                     maleCandidates.Pop();
  31.                     matches++;
  32.                 }
  33.  
  34.                 else
  35.                 {
  36.                     femaleCandidates.Dequeue();
  37.  
  38.                     maleCandidates.Push(maleCandidates.Pop() - 2);
  39.                 }
  40.  
  41.                 maleCandidates = new Stack<int>(RefineMatches(maleCandidates.ToList()));
  42.  
  43.                 maleCandidates = Reverse(maleCandidates);
  44.  
  45.                 femaleCandidates = new Queue<int>(RefineMatches(femaleCandidates.ToList()));
  46.             }
  47.  
  48.  
  49.             Console.WriteLine($"Matches: {matches}");
  50.             string maleMatches = maleCandidates.Count == 0 ? "none" : String.Join(", ", maleCandidates);
  51.             string femaleMatches = femaleCandidates.Count == 0 ? "none" : String.Join(", ", femaleCandidates);
  52.  
  53.             Console.WriteLine("Males left: " + maleMatches);
  54.             Console.WriteLine("Females left: " + femaleMatches);
  55.  
  56.         }
  57.  
  58.         public static Stack<int> Reverse(Stack<int> input)
  59.         {
  60.             //Declare another stack to store the values from the passed stack
  61.             Stack<int> temp = new Stack<int>();
  62.  
  63.             //While the passed stack isn't empty, pop elements from the passed stack onto the temp stack
  64.             while (input.Count != 0)
  65.             {
  66.                 temp.Push(input.Pop());
  67.             }
  68.  
  69.             return temp;
  70.         }
  71.  
  72.         private static List<int> RefineMatches(List<int> people)
  73.         {
  74.  
  75.             people.RemoveAll(x => x <= 0);
  76.  
  77.             for (int i = 0; i < people.Count; i++)
  78.             {
  79.                 if (people[i] % 25 == 0)
  80.                 {
  81.                     people.RemoveAt(i);
  82.  
  83.                     if (i < people.Count)
  84.                     {
  85.                         people.RemoveAt(i);
  86.                     }
  87.  
  88.                 }
  89.             }
  90.  
  91.  
  92.             return people;
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement