SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.*; | |
| 2 | import java.util.stream.Collectors; | |
| 3 | ||
| 4 | public class demo {
| |
| 5 | public static void main(String[] args) {
| |
| 6 | Scanner scanner = new Scanner(System.in); | |
| 7 | int countCommands = Integer.parseInt(scanner.nextLine()); | |
| 8 | List<String> names = new ArrayList<>(); | |
| 9 | for (int i = 1; i <= countCommands ; i++) {
| |
| 10 | String command = scanner.nextLine(); | |
| 11 | //"{name} is going!" -> добавяме ако го няма; ако го има -> печатаме ...
| |
| 12 | //"{name} is not going!" -> ако го има -> махаме; ако го няма -> печатаме
| |
| 13 | String [] tokens = command.split("\\s+");
| |
| 14 | //["{name}, "is", "going!"]
| |
| 15 | //["{name}, "is", "not", "going!"]
| |
| 16 | String name = tokens[0]; | |
| 17 | if(tokens[2].equals("going!")) { //Going :)
| |
| 18 | if(names.contains(name)) {
| |
| 19 | System.out.printf("%s is already in the list!%n", name);
| |
| 20 | } else {
| |
| 21 | names.add(name); | |
| 22 | } | |
| 23 | } else if (tokens[2].equals("not")) { //Not Going :(
| |
| 24 | if(names.contains(name)) {
| |
| 25 | names.remove(name); | |
| 26 | } else {
| |
| 27 | System.out.printf("%s is not in the list!%n", name);
| |
| 28 | } | |
| 29 | } | |
| 30 | ||
| 31 | } | |
| 32 | printList(names); | |
| 33 | ||
| 34 | } | |
| 35 | ||
| 36 | private static void printList(List<String> names) {
| |
| 37 | for (String name : names) {
| |
| 38 | System.out.println(name); | |
| 39 | } | |
| 40 | } | |
| 41 | } |