Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 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.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. } else if (tokens[1].equals("is") && tokens[2].equals("not") && tokens[3].equals("going!")) {
  34. isNotGoing.add(tokens[0]);
  35. if (isGoing.contains(tokens[0])) {
  36. isGoing.remove(tokens[0]);
  37. isNotGoing.remove(tokens[0]);
  38.  
  39. }
  40.  
  41.  
  42.  
  43. }
  44. else{
  45. break;
  46. }
  47. }
  48. Set<String> s = new LinkedHashSet<>(isGoing);
  49.  
  50. for(String name:alreadyOnList){
  51. if(isGoing.contains(name)) {
  52. // isGoing.remove(name);
  53. System.out.println(name + " is already in the list!");
  54.  
  55.  
  56. }
  57. }
  58. for(String name2:isNotGoing) {
  59. if (!alreadyOnList.contains(name2)) {
  60. System.out.println(name2 + " is not in the list!");
  61.  
  62. }
  63.  
  64. }
  65. for(String name3:s){
  66. System.out.println(name3);
  67.  
  68.  
  69. }
  70.  
  71.  
  72.  
  73.  
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement