Advertisement
Guest User

Untitled

a guest
Dec 6th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. package FinalExamPrep04April2020Group1;
  2.  
  3. import java.math.BigInteger;
  4. import java.util.HashMap;
  5. import java.util.LinkedHashMap;
  6. import java.util.Map;
  7. import java.util.Scanner;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10.  
  11. public class EmojiDetector02 {
  12.     public static void main(String[] args) {
  13.  
  14.         Scanner scanner = new Scanner(System.in);
  15.  
  16.         String input = scanner.nextLine();
  17.         String emojiRegex = "([:*]{2,})([A-Z][a-z]{2,})\\1";
  18.         String digitRegex = "\\d";
  19.  
  20.         Pattern emojiPattern = Pattern.compile(emojiRegex);
  21.  
  22.         Pattern digitPattern = Pattern.compile(digitRegex);
  23.  
  24.         int count = 0;
  25.         int coolnessThreshold = 1;
  26.         Boolean isCool = false;
  27.  
  28.         Matcher matchDigits = digitPattern.matcher(input);
  29.         while (matchDigits.find()) {
  30.             coolnessThreshold *= Integer.parseInt(matchDigits.group());
  31.         }
  32.  
  33.         Map<String, Integer> coolEmojis = new LinkedHashMap<>();
  34.  
  35.         Matcher matchEmoji = emojiPattern.matcher(input);
  36.         while (matchEmoji.find()) {
  37.             count++;
  38.             int coolness = 0;
  39.             String currentMatch = matchEmoji.group(2);
  40.             for (int i = 0; i < currentMatch.length(); i++) {
  41.                 char x = currentMatch.charAt(i);
  42.                 coolness += x;
  43.             }
  44.             if (coolness > coolnessThreshold) {
  45.                 isCool = true;
  46.                 coolEmojis.put(matchEmoji.group(), coolness);
  47.             }
  48.         }
  49.         System.out.println("Cool threshold: " + coolnessThreshold);
  50.         System.out.println(count + " emojis found in the text. The cool ones are:");
  51.  
  52.         if(isCool) {
  53.             for (String s : coolEmojis.keySet()) {
  54.                 System.out.println(s);
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement