// package seupackage.
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
public class Main {
public static class Party {
private final Set<String> players;
public Party() {
this.players = new LinkedHashSet<>();
}
public void toggle
(String player
) { if (players.contains(player)) {
players.remove(player);
} else {
players.add(player);
}
}
return players.
toArray(new String[players.
size()]); }
public Set<String> toSet() {
return new LinkedHashSet<>(players);
}
}
public static void main
(String[] args
) { Party p = new Party();
p.toggle("Pedro"); // Adiciona o Pedro
System.
out.
println(Arrays.
asList(p.
toArray())); // Imprime [Pedro] p.toggle("Maria"); // Adiciona a Maria
System.
out.
println(Arrays.
asList(p.
toArray())); // Imprime [Pedro, Maria] p.toggle("Pedro"); // Remove o Pedro
System.
out.
println(Arrays.
asList(p.
toArray())); // Imprime [Maria] p.toggle("Carlos"); // Adiciona o Carlos
p.toggle("Fernando"); // Adiciona o Fernando
System.
out.
println(p.
toSet()); // Imprime [Maria, Carlos, Fernando] p.toggle("Carlos"); // Remove o Carlos
System.
out.
println(p.
toSet()); // Imprime [Maria, Fernando] }
}
Ly8gcGFja2FnZSBzZXVwYWNrYWdlLgoKaW1wb3J0IGphdmEudXRpbC5BcnJheXM7CmltcG9ydCBqYXZhLnV0aWwuTGlua2VkSGFzaFNldDsKaW1wb3J0IGphdmEudXRpbC5TZXQ7CgpwdWJsaWMgY2xhc3MgTWFpbiB7CgogICAgcHVibGljIHN0YXRpYyBjbGFzcyBQYXJ0eSB7CgogICAgICAgIHByaXZhdGUgZmluYWwgU2V0PFN0cmluZz4gcGxheWVyczsKCiAgICAgICAgcHVibGljIFBhcnR5KCkgewogICAgICAgICAgICB0aGlzLnBsYXllcnMgPSBuZXcgTGlua2VkSGFzaFNldDw+KCk7CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgdm9pZCB0b2dnbGUoU3RyaW5nIHBsYXllcikgewogICAgICAgICAgICBpZiAocGxheWVycy5jb250YWlucyhwbGF5ZXIpKSB7CiAgICAgICAgICAgICAgICBwbGF5ZXJzLnJlbW92ZShwbGF5ZXIpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGxheWVycy5hZGQocGxheWVyKTsKICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgcHVibGljIFN0cmluZ1tdIHRvQXJyYXkoKSB7CiAgICAgICAgICAgcmV0dXJuIHBsYXllcnMudG9BcnJheShuZXcgU3RyaW5nW3BsYXllcnMuc2l6ZSgpXSk7CiAgICAgICAgfQoKICAgICAgICBwdWJsaWMgU2V0PFN0cmluZz4gdG9TZXQoKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgTGlua2VkSGFzaFNldDw+KHBsYXllcnMpOwogICAgICAgIH0KICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgUGFydHkgcCA9IG5ldyBQYXJ0eSgpOwogICAgICAgIHAudG9nZ2xlKCJQZWRybyIpOyAvLyBBZGljaW9uYSBvIFBlZHJvCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKEFycmF5cy5hc0xpc3QocC50b0FycmF5KCkpKTsgLy8gSW1wcmltZSBbUGVkcm9dCiAgICAgICAgcC50b2dnbGUoIk1hcmlhIik7IC8vIEFkaWNpb25hIGEgTWFyaWEKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oQXJyYXlzLmFzTGlzdChwLnRvQXJyYXkoKSkpOyAvLyBJbXByaW1lIFtQZWRybywgTWFyaWFdCiAgICAgICAgcC50b2dnbGUoIlBlZHJvIik7IC8vIFJlbW92ZSBvIFBlZHJvCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKEFycmF5cy5hc0xpc3QocC50b0FycmF5KCkpKTsgLy8gSW1wcmltZSBbTWFyaWFdCiAgICAgICAgcC50b2dnbGUoIkNhcmxvcyIpOyAvLyBBZGljaW9uYSBvIENhcmxvcwogICAgICAgIHAudG9nZ2xlKCJGZXJuYW5kbyIpOyAvLyBBZGljaW9uYSBvIEZlcm5hb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