Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mid.exam;
- import java.util.Arrays;
- import java.util.HashMap;
- import java.util.Scanner;
- import java.util.TreeMap;
- import java.util.concurrent.atomic.AtomicInteger;
- public class Problem2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- String[] arr = input.split(", ");
- int blackisted = 0, lost = 0;
- while(!input.equals("Report")){
- input = sc.nextLine();
- String[] command = input.split(" ");
- switch (command[0]){
- case "Blacklist": {
- boolean found = false;
- for (int i = 0; i < arr.length; i++) {
- if (arr[i].equals(command[1]) && !found){
- arr[i] = "Blacklisted";
- System.out.println(command[1] + " was blacklisted.");
- found = true;
- blackisted++;
- }
- }
- if(!found){
- System.out.println(command[1] + " was not found.");
- }
- break;
- }
- case "Error": {
- for (int i = 0; i < arr.length; i++) {
- if (Integer.parseInt(command[1])==i && !arr[i].equals("Blacklisted") && !arr[i].equals("Lost")){
- System.out.println(arr[i] + " was lost due to an error.");
- arr[i] = "Lost";
- lost++;
- }
- }
- break;
- }
- case "Change":{
- for (int i = 0; i < arr.length; i++) {
- if (Integer.parseInt(command[1])==i){
- System.out.println(arr[i] + " changed his username to " + command[2] + ".");
- arr[i] = command[2];
- }
- }
- break;
- }
- }
- }
- System.out.println("Blacklisted names: " + blackisted);
- System.out.println("Lost names: " + lost);
- for (String el: arr) {
- System.out.print(el + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement