ilianrusev

Present Delivery

Mar 9th, 2019
87
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3.  
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6.  
  7.  
  8. public class Main {
  9.  
  10. public static void main(String[] args) {
  11. Scanner scanner = new Scanner(System.in);
  12.  
  13. List<Integer> members = Arrays.stream(scanner.nextLine().split("@"))
  14. .map(Integer::parseInt)
  15. .collect(Collectors.toList());
  16.  
  17. List<String> commands = Arrays.stream(scanner.nextLine().split(" "))
  18. .collect(Collectors.toList());
  19. int position = 1;
  20. boolean allEqual = true;
  21. int count = 0;
  22. int house = 0;
  23.  
  24. System.out.println();
  25. while (!commands.contains("Merry")){
  26.  
  27. String jump1 = commands.get(1);
  28. int jump = Integer.parseInt(jump1);
  29.  
  30. position += jump;
  31.  
  32. if (position > members.size()){
  33. position = position % members.size();
  34. }
  35. house = position-1;
  36. if (members.get(house) == 0){
  37. System.out.printf("House %d will have a Merry Christmas.\n",
  38. members.indexOf(members.get(house)));
  39. }else {
  40. members.set(position - 1, members.get(house) - 2);
  41. }
  42.  
  43. commands=Arrays.stream(scanner.nextLine().split(" "))
  44. .collect(Collectors.toList());
  45. }
  46.  
  47.  
  48.  
  49. System.out.printf("Santa's last position was %d.\n",house);
  50. for (int i = 1; i < members.size(); i++) {
  51. if (!members.get(0).equals(members.get(i))){
  52. allEqual = false;
  53. }
  54. }
  55. if (allEqual){
  56. System.out.println("Mission was successful.");
  57. }else{
  58. for (int i = 1; i < members.size(); i++) {
  59. if (members.get(1) != 0){
  60. count +=1;
  61. }
  62. }
  63. System.out.printf("Santa has failed %d houses.",count);
  64. }
  65. }
  66. }
RAW Paste Data Copied