Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. package datingApp;
  2. import java.util.ArrayDeque;
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5. public class DatingApp {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner (System.in);
  8.  
  9. int[] maleInfo = Arrays.stream(scanner.nextLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
  10. ArrayDeque<Integer> maleStack = new ArrayDeque<>();
  11. Arrays.stream(maleInfo).forEach(maleStack::push);
  12. int[] femaleInfo = Arrays.stream(scanner.nextLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
  13. ArrayDeque<Integer> femaleQueue = new ArrayDeque<>();
  14. Arrays.stream(femaleInfo).forEach(femaleQueue::offer);
  15.  
  16. int matches = 0;
  17. while (femaleQueue.size()!=0 && maleStack.size()!=0){
  18. int currFemale = femaleQueue.peek();
  19. int currMale = maleStack.peek();
  20. if (currFemale<=0 ){
  21. femaleQueue.poll();
  22. continue;
  23. }else if (currFemale%25 ==0){
  24. femaleQueue.poll();
  25. if (femaleQueue.size()!=0){
  26. femaleQueue.poll();
  27. }
  28. continue;
  29. }
  30. if (currMale<=0){
  31. maleStack.pop();
  32. continue;
  33. }else if (currMale%25==0){
  34. maleStack.pop();
  35. if (maleStack.size()!=0){
  36. maleStack.pop();
  37. }
  38. continue;
  39. }
  40. if (currFemale==currMale){
  41. matches++;
  42. maleStack.pop();
  43. }else {
  44. currMale-=2;
  45. maleStack.pop();
  46. maleStack.push(currMale);
  47. }
  48. femaleQueue.poll();
  49. }
  50.  
  51. System.out.println("Matches: " + matches);
  52. if (maleStack.size()==0){
  53. System.out.println("Males left: none");
  54. }else{
  55. System.out.print("Males left: ");
  56. printDeque(maleStack);
  57. }
  58. if (femaleQueue.size()==0){
  59. System.out.println("Females left: none");
  60. }else {
  61. System.out.print("Females left: ");
  62. printDeque(femaleQueue);
  63. }
  64. }
  65.  
  66. private static void printDeque(ArrayDeque<Integer> deque) {
  67. int n = deque.size();
  68. for (int i = 0; i < n-1; i++) {
  69. System.out.print(deque.pop() + ", ");
  70. }
  71. System.out.println(deque.pop());
  72. }
  73.  
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement