Advertisement
Guest User

Emoji

a guest
Apr 4th, 2020
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.LinkedHashMap;
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class EmojiDetector {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         String text = scanner.nextLine();
  11.         String regexValidWords = "(?<a>[:*]{2})(?<word>[A-Z][a-z]{2,})\\k<a>";
  12.         String threshold = "[\\d]";
  13.  
  14.  
  15.         Pattern pattern = Pattern.compile(threshold);
  16.         Matcher matcher = pattern.matcher(text);
  17.         long total = 1;
  18.         while (matcher.find()) {
  19.             int combine = Integer.parseInt(matcher.group());
  20.             total *= combine;
  21.         }
  22.  
  23.         ArrayList<String> coolList = new ArrayList<>();
  24.         Pattern p = Pattern.compile(regexValidWords);
  25.         Matcher m = p.matcher(text);
  26.         int emojisInText = 0;
  27.         while (m.find()) {
  28.             String fullWordMatched = m.group();
  29.             String matched = m.group("word");
  30.             int sum = 0;
  31.             for (int i = 0; i < matched.length(); i++) {
  32.                 char ascii = matched.charAt(i);
  33.                 sum += ascii;
  34.             }
  35.             if (sum > total) {
  36.                 coolList.add(fullWordMatched);
  37.             }
  38.             emojisInText++;
  39.         }
  40.         System.out.println(String.format("Cool threshold: %d", total));
  41.         System.out.println(String.format("%d emojis found in the text. The cool ones are:", emojisInText));
  42.         for (String s : coolList) {
  43.             System.out.println(s);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement