Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://www.reddit.com/r/BlueBeetleHqFre/
- https://www.reddit.com/r/Strayshqfre
- https://www.reddit.com/r/HauntingQueenMaryHqf
- https://www.reddit.com/r/TheMoonhqfre
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String inputStr = scanner.nextLine();
- String regex = "(?<index>[\\\\|\\\\#]{1})(?<item>[A-z\\s+]+)\\1(?<date>[0-9]{2}[\\/]{1}[0-9]{2}[\\/]{1}[0-9]{2})\\1(?<calories>\\d{1,5})\\1";
- Pattern pattern = Pattern.compile(regex);
- int days = 0;
- HashMap<String, Integer> foodCalories = new HashMap<String, Integer>();
- Matcher matcher = pattern.matcher(inputStr);
- while (matcher.find()) {
- String item = matcher.group("item");
- int current = Integer.parseInt(matcher.group("calories"));
- foodCalories.put(item, current);
- days += current;
- }
- System.out.println("You have food to last you for: " + (days / 2000) + " days!");
- matcher = pattern.matcher(inputStr);
- while (matcher.find()) {
- String item = matcher.group("item");
- String date = matcher.group("date");
- int calories = Integer.parseInt(matcher.group("calories"));
- System.out.println("Item: " + item + ", Best before: " + date + ", Nutrition: " + calories);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement