Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class TaskPlanner {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] values = scanner.nextLine().split("\\s+");
- List<Integer> hours = new ArrayList<>();
- int countCompleted=0;
- int countIncomplete=0;
- int countDropped=0;
- for (int i = 0; i < values.length; i++) {
- hours.add(Integer.parseInt(values[i]));
- }
- String command = scanner.nextLine();
- while (!command.equals("End")) {
- String[] operations = command.split("\\s+");
- if (operations[0].equals("Complete")) {
- int index = Integer.parseInt(operations[1]);
- if (index < hours.size()) {
- hours.set(index, 0);
- }
- } else if (operations[0].equals("Change")) {
- int index = Integer.parseInt(operations[1]);
- int newHour = Integer.parseInt(operations[2]);
- if (index < hours.size()) {
- hours.set(index, newHour);
- }
- } else if (operations[0].equals("Drop")) {
- int index = Integer.parseInt(operations[1]);
- if (index < hours.size()) {
- hours.set(index, -1);
- }
- } else if (operations[1].equals("Completed")) {
- for (Integer hour : hours) {
- int count=0;
- if (hour == 0) {
- countCompleted++;
- }
- }
- System.out.printf("%d%n", countCompleted);
- } else if (operations[1].equals("Incomplete")) {
- for (Integer hour : hours) {
- int count=0;
- if (hour > 0) {
- countIncomplete++;
- }
- }
- System.out.printf("%d%n", countIncomplete);
- } else if (operations[1].equals("Dropped")) {
- for (Integer hour : hours) {
- int count=0;
- if (hour < 0) {
- countDropped++;
- }
- }
- System.out.printf("%d%n", countDropped);
- }
- command = scanner.nextLine();
- }
- for (Integer hour : hours) {
- if (hour > 0) {
- System.out.print(hour + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement