Advertisement
purshink

Emoji Detector

Apr 8th, 2020
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. package New;
  2.  
  3. import org.w3c.dom.ls.LSOutput;
  4.  
  5. import java.math.BigDecimal;
  6. import java.util.*;
  7. import java.util.regex.Matcher;
  8. import java.util.regex.Pattern;
  9.  
  10. public class Test {
  11.     public static void main(String[] args) {
  12.         Scanner scan = new Scanner(System.in);
  13.         String string = scan.nextLine();
  14.  
  15.         Pattern pattern = Pattern.compile("([:*]{2})(?<emojy>[A-Z][a-z]{2,})(\\1)");
  16.         Pattern numbers =Pattern.compile("[0-9]");
  17.         Matcher patternMatcher = pattern.matcher(string);
  18.         Matcher numbersMatcher = numbers.matcher(string);
  19.         BigDecimal coolT = new BigDecimal(1);
  20.         ArrayList<String> coolEm = new ArrayList<>();
  21.  
  22.         while (numbersMatcher.find()){
  23.             int num = Integer.parseInt(numbersMatcher.group(0));
  24.             coolT = coolT.multiply(BigDecimal.valueOf(num));
  25.         }
  26.  
  27.         int emCounter = 0;
  28.         while (patternMatcher.find()){
  29.             String emojy = patternMatcher.group("emojy");
  30.             BigDecimal coolness = new BigDecimal(0);
  31.  
  32.             Pattern letters = Pattern.compile("[A-Za-z]");
  33.             Matcher letterMatcher = letters.matcher(emojy);
  34.  
  35.             while (letterMatcher.find()) {
  36.                 char value = letterMatcher.group(0).charAt(0);
  37.                 coolness = coolness.add(BigDecimal.valueOf(value));
  38.             }
  39.             if (coolness.compareTo(coolT)==0 || coolness.compareTo(coolT)==1){
  40.  
  41.                 coolEm.add(patternMatcher.group(1) + patternMatcher.group("emojy") + patternMatcher.group(3));
  42.             }
  43.             emCounter++;
  44.         }
  45.         System.out.println("Cool threshold: " + coolT);
  46.         System.out.println( emCounter + " emojis found in the text. The cool ones are:");
  47.         for (String s : coolEm) {
  48.             System.out.println(s );
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement