Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Arrays;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class EmojiSumator {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String text = sc.nextLine();
- int[] numbers = Arrays.stream(sc.nextLine().split(":"))
- .mapToInt(e -> Integer.parseInt(e))
- .toArray();
- // double[] nums = Arrays.stream(sc.nextLine().split("\\s+")).mapToDouble(Double::parseDouble).toArray();
- String regex = "(?<=\\s):([a-z]{4,}):[?=\\s,.!?]";
- String regex2 = "(?<=\\s)(:[a-z]{4,}:)[?=\\s,.!?]";
- Pattern pattern = Pattern.compile(regex);
- Pattern patternColons = Pattern.compile(regex2);
- Matcher matcher = pattern.matcher(text);
- int emojiTotalValue = 0;
- int emojiValue = 0;
- List<Integer> emojiCodes = new LinkedList<>();
- List<String> emojis = new LinkedList<>();
- List<String> emojisColons = new LinkedList<>();
- while (matcher.find()) {
- int length = matcher.group(1).length();
- emojis.add(matcher.group(1));
- for (int i = 0; i < length; i++) {
- int value = matcher.group(1).charAt(i);
- emojiTotalValue += value;
- emojiValue += value;
- }
- emojiCodes.add(emojiValue);
- emojiValue = 0;
- // matcher = pattern.matcher(text);
- }
- matcher = patternColons.matcher(text);
- while (matcher.find()) {
- emojisColons.add(matcher.group(1));
- }
- int sum = 0;
- for (int number : numbers) {
- sum += number;
- }
- if (emojiCodes.contains(sum)) {
- emojiTotalValue *= 2;
- }
- if (!emojisColons.isEmpty()) {
- System.out.print("Emojis found: ");
- System.out.println(String.join(", ", emojisColons));
- }
- // System.out.println();
- System.out.printf("Total Emoji Power: %d", emojiTotalValue);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement