Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. public class HouseParty {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7. int names = Integer.parseInt(scanner.nextLine());
  8. List<String> isGoing = new ArrayList<>();
  9. List<String> isNotGoing = new ArrayList<>();
  10. List<String> alreadyOnList = new ArrayList<>();
  11. String[] tokens = new String[0];
  12. for (int i = 0; i < names; i++) {
  13.  
  14. String whosGoingorNot = scanner.nextLine();
  15. tokens = whosGoingorNot.split(" ");
  16. if (tokens[1].equals("is") && tokens[2].equals("going!")) {
  17.  
  18. if (isGoing.contains(tokens[0])) {
  19. alreadyOnList.add(tokens[0]);
  20.  
  21.  
  22. }
  23. isGoing.add(tokens[0]);
  24.  
  25.  
  26. } else if (tokens[1].equals("is") && tokens[2].equals("not") && tokens[3].equals("going!")) {
  27. isNotGoing.add(tokens[0]);
  28. if (isGoing.contains(tokens[0])) {
  29. isGoing.remove(tokens[0]);
  30. isNotGoing.remove(tokens[0]);
  31.  
  32. }
  33.  
  34.  
  35. } else {
  36. break;
  37. }
  38. }
  39. Set<String> s = new LinkedHashSet<>(isGoing);
  40.  
  41. for (String name : alreadyOnList) {
  42. if (isGoing.contains(name)) {
  43. // isGoing.remove(name);
  44. System.out.println(name + " is already in the list!");
  45.  
  46.  
  47. }
  48. }
  49. for (String name2 : isNotGoing) {
  50. if (!alreadyOnList.contains(name2)) {
  51. System.out.println(name2 + " is not in the list!");
  52. break;
  53.  
  54. }
  55.  
  56. }
  57. for (String name3 : s) {
  58. System.out.println(name3);
  59.  
  60.  
  61. }
  62.  
  63.  
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement