Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package OldExams;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class ChoreWars {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String line = reader.readLine();
- int dishesTime = 0;
- int cleaningTime = 0;
- int laundryTime = 0;
- int totalTime = 0;
- Pattern patternDishes = Pattern.compile("<([a-z\\d]+)>");
- Matcher matcherDishes = patternDishes.matcher(line);
- Pattern patternCleaning = Pattern.compile("\\[([A-Z\\d]+)\\]");
- Matcher matcherCleaning = patternCleaning.matcher(line);
- Pattern patternLaundry = Pattern.compile("\\{(.+)}");
- Matcher matcherLaundry = patternLaundry.matcher(line);
- String dishes = "";
- String cleaning = "";
- String laundry = "";
- while (!line.equals("wife is happy")){
- if (matcherDishes.find()){
- dishes += matcherDishes.group();
- for (int i = 0; i < dishes.length(); i++) {
- char symbol = dishes.charAt(i);
- if (Character.isDigit(symbol)){
- dishesTime += Character.getNumericValue(symbol);
- }
- }
- } else if (matcherCleaning.find()){
- cleaning += matcherCleaning.group();
- for (int i = 0; i < cleaning.length(); i++) {
- char symbol = cleaning.charAt(i);
- if (Character.isDigit(symbol)){
- cleaningTime += Character.getNumericValue(symbol);
- }
- }
- } else if (matcherLaundry.find()){
- laundry += matcherLaundry.group();
- for (int i = 0; i < laundry.length(); i++) {
- char symbol = laundry.charAt(i);
- if (Character.isDigit(symbol)){
- laundryTime += symbol;
- }
- }
- }
- line = reader.readLine();
- }
- totalTime = dishesTime + cleaningTime + laundryTime;
- System.out.println("Doing the dishes - " + dishesTime + " min.");
- System.out.println("Cleaning the house - " + cleaningTime + " min.");
- System.out.println("Doing the laundry - " + laundryTime + " min.");
- System.out.println("Total - " + totalTime + " min.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement