Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class _03_ChoreWars {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String dishes = "<([a-z0-9]+)>";
- String cleaning = "\\[([A-Z0-9]+)]";
- String laundry = "\\{(.+)}";
- Pattern pDishes = Pattern.compile(dishes);
- Pattern pCleaning = Pattern.compile(cleaning);
- Pattern pLaundry = Pattern.compile(laundry);
- String input = "";
- int countDish = 0;
- int countClean = 0;
- int countLaundry = 0;
- while (!"wife is happy".equals(input = scanner.nextLine())) {
- Matcher mDishes = pDishes.matcher(input);
- Matcher mCleaning = pCleaning.matcher(input);
- Matcher mLaundry = pLaundry.matcher(input);
- if(mDishes.find()){
- String dishesCounting = mDishes.group(1);
- for (int i = 0; i < dishesCounting.length(); i++) {
- if(Character.isDigit(dishesCounting.charAt(i))){
- String one = "" + dishesCounting.charAt(i);
- countDish += Integer.parseInt(one);
- }
- }
- }
- if (mCleaning.find()){
- String cleanCounting = mCleaning.group(1);
- for (int i = 0; i < cleanCounting.length(); i++) {
- if(Character.isDigit(cleanCounting.charAt(i))){
- String two = "" + cleanCounting.charAt(i);
- countClean += Integer.parseInt(two);
- }
- }
- }
- if (mLaundry.find()){
- String laundryCounting = mLaundry.group(1);
- for (int i = 0; i < laundryCounting.length(); i++) {
- if(Character.isDigit(laundryCounting.charAt(i))){
- String three = "" + laundryCounting.charAt(i);
- countLaundry += Integer.parseInt(three);
- }
- }
- }
- }
- System.out.println("Doing the dishes - " + countDish + " min.");
- System.out.println("Cleaning the house - " + countClean + " min.");
- System.out.println("Doing the laundry - " + countLaundry + " min.");
- System.out.println("Total - " + (countDish + countClean + countLaundry) + " min.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement