Advertisement
Edzhevit

Chore Wars

Dec 10th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.57 KB | None | 0 0
  1. package OldExams;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class ChoreWars {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.         String line = reader.readLine();
  13.  
  14.         int dishesTime = 0;
  15.         int cleaningTime = 0;
  16.         int laundryTime = 0;
  17.         int totalTime = 0;
  18.  
  19.         Pattern patternDishes = Pattern.compile("<([a-z\\d]+)>");
  20.         Matcher matcherDishes = patternDishes.matcher(line);
  21.  
  22.         Pattern patternCleaning = Pattern.compile("\\[([A-Z\\d]+)\\]");
  23.         Matcher matcherCleaning = patternCleaning.matcher(line);
  24.  
  25.         Pattern patternLaundry = Pattern.compile("\\{(.+)}");
  26.         Matcher matcherLaundry = patternLaundry.matcher(line);
  27.  
  28.  
  29.         String dishes = "";
  30.         String cleaning = "";
  31.         String laundry = "";
  32.         while (!line.equals("wife is happy")){
  33.             if (matcherDishes.find()){
  34.                 dishes += matcherDishes.group();
  35.                 for (int i = 0; i < dishes.length(); i++) {
  36.                     char symbol = dishes.charAt(i);
  37.                     if (Character.isDigit(symbol)){
  38.                         dishesTime += Character.getNumericValue(symbol);
  39.                     }
  40.  
  41.                 }
  42.             } else if (matcherCleaning.find()){
  43.                 cleaning += matcherCleaning.group();
  44.                 for (int i = 0; i < cleaning.length(); i++) {
  45.                     char symbol = cleaning.charAt(i);
  46.                     if (Character.isDigit(symbol)){
  47.                         cleaningTime += Character.getNumericValue(symbol);
  48.                     }
  49.  
  50.                 }
  51.             } else if (matcherLaundry.find()){
  52.                 laundry += matcherLaundry.group();
  53.                 for (int i = 0; i < laundry.length(); i++) {
  54.                     char symbol = laundry.charAt(i);
  55.                     if (Character.isDigit(symbol)){
  56.                         laundryTime += symbol;
  57.                     }
  58.  
  59.                 }
  60.             }
  61.  
  62.             line = reader.readLine();
  63.         }
  64.  
  65.         totalTime = dishesTime + cleaningTime + laundryTime;
  66.  
  67.         System.out.println("Doing the dishes - " + dishesTime + " min.");
  68.         System.out.println("Cleaning the house - " + cleaningTime + " min.");
  69.         System.out.println("Doing the laundry - " + laundryTime + " min.");
  70.         System.out.println("Total - " + totalTime + " min.");
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement