Advertisement
Guest User

Untitled

a guest
Aug 13th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace DatingApp
  6. {
  7.     class Program
  8.     {
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.             Stack<int> male = new Stack<int>(Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray());
  13.             Queue<int> female = new Queue<int>(Console.ReadLine().Split(" ",StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray());
  14.             int matchCount = 0;
  15.             while (female.Any() || female.Any())
  16.             {
  17.                 int currMale = male.Peek();
  18.                 int currFemale = female.Peek();
  19.  
  20.  
  21.                 if (currFemale <= 0)
  22.                 {
  23.                     female.Dequeue();
  24.                     continue;
  25.                 }
  26.  
  27.                 if (currMale <= 0)
  28.                 {
  29.                     male.Pop();
  30.                     continue;
  31.                 }
  32.  
  33.                 if (currFemale == currMale)
  34.                 {
  35.                     male.Pop();
  36.                     female.Dequeue();
  37.                     matchCount++;
  38.                 }
  39.                 else if (currFemale != currMale)
  40.                 {
  41.                     female.Dequeue();
  42.                     int m = male.Peek() - 2;//before or after dequene
  43.                     male.Pop();
  44.                     male.Push(m);
  45.  
  46.                 }
  47.  
  48.                 if (currFemale % 25 == 0)
  49.                 {
  50.                     female.Dequeue();
  51.                     male.Pop();
  52.                     male.Pop();
  53.                 }
  54.                 if (currMale % 25 == 0)
  55.                 {
  56.                     male.Pop();
  57.                     female.Dequeue();
  58.                     female.Dequeue();
  59.  
  60.                 }
  61.  
  62.                 if (male.Count == 0 || female.Count == 0)
  63.                 {
  64.                     break;
  65.                 }
  66.  
  67.             }
  68.  
  69.             Console.WriteLine($"Matches: {matchCount}");
  70.             if (female.Any())
  71.             {
  72.                 Console.WriteLine($"Males left: {string.Join(", ", female)}");
  73.             }
  74.             else
  75.             {
  76.                 Console.WriteLine($"Males left: none");
  77.             }
  78.             if (female.Any())
  79.             {
  80.                 Console.WriteLine($"Females left: {string.Join(", ", female)}");
  81.             }
  82.             else
  83.             {
  84.                 Console.WriteLine($"Females left: none");
  85.             }
  86.         }
  87.     }
  88. }
  89.  
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement