Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Exam27OctProblem1
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> males = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- List<int> females = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
- males = RefineMatches(males);
- females = RefineMatches(females);
- Stack<int> maleCandidates = new Stack<int>(males);
- Queue<int> femaleCandidates = new Queue<int>(females);
- int matches = 0;
- while (femaleCandidates.Count != 0 && maleCandidates.Count != 0)
- {
- int girl = femaleCandidates.Peek();
- int guy = maleCandidates.Peek();
- if (girl == guy)
- {
- femaleCandidates.Dequeue();
- maleCandidates.Pop();
- matches++;
- }
- else
- {
- femaleCandidates.Dequeue();
- maleCandidates.Push(maleCandidates.Pop() - 2);
- }
- maleCandidates = new Stack<int>(RefineMatches(maleCandidates.ToList()));
- maleCandidates = Reverse(maleCandidates);
- femaleCandidates = new Queue<int>(RefineMatches(femaleCandidates.ToList()));
- }
- Console.WriteLine($"Matches: {matches}");
- string maleMatches = maleCandidates.Count == 0 ? "none" : String.Join(", ", maleCandidates);
- string femaleMatches = femaleCandidates.Count == 0 ? "none" : String.Join(", ", femaleCandidates);
- Console.WriteLine("Males left: " + maleMatches);
- Console.WriteLine("Females left: " + femaleMatches);
- }
- public static Stack<int> Reverse(Stack<int> input)
- {
- //Declare another stack to store the values from the passed stack
- Stack<int> temp = new Stack<int>();
- //While the passed stack isn't empty, pop elements from the passed stack onto the temp stack
- while (input.Count != 0)
- {
- temp.Push(input.Pop());
- }
- return temp;
- }
- private static List<int> RefineMatches(List<int> people)
- {
- people.RemoveAll(x => x <= 0);
- for (int i = 0; i < people.Count; i++)
- {
- if (people[i] % 25 == 0)
- {
- people.RemoveAt(i);
- if (i < people.Count)
- {
- people.RemoveAt(i);
- }
- }
- }
- return people;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement