Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Ex2 {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         String input = scanner.nextLine();
  12.  
  13.         Pattern regex = Pattern.compile("([:]{2}|[*]{2})(?<emoji>[A-Z][a-z]{2,})(\\1)");
  14.         Pattern regex1 = Pattern.compile("[\\d]");
  15.  
  16.         Matcher matcher = regex.matcher(input);
  17.         Matcher matcher1 = regex1.matcher(input);
  18.  
  19.         long coolThreshold = 1;
  20.  
  21.         while (matcher1.find()){
  22.             int digits = Integer.parseInt(matcher1.group(0));
  23.  
  24.             coolThreshold *= digits;
  25.         }
  26.  
  27.         System.out.printf("Cool threshold: %d%n", coolThreshold);
  28.  
  29.         List<String> cool = new ArrayList<>();
  30.  
  31.         int coolness = 0;
  32.         int count = 0;
  33.         while (matcher.find()){
  34.  
  35.             String emoji = matcher.group("emoji");
  36.             String group1 = matcher.group(1);
  37.  
  38.             coolness = 0;
  39.             count++;
  40.             for (int i = 0; i < emoji.length() ; i++) {
  41.                 char letter = emoji.charAt(i);
  42.                 coolness += letter;
  43.             }
  44.  
  45.             if (coolness > coolThreshold){
  46.                 cool.add(group1 + emoji + group1);
  47.             }
  48.  
  49. //            System.out.println(emoji);
  50.  
  51.         }
  52.  
  53.         System.out.printf("%d emojis found in the text. The cool ones are:%n", count);
  54.  
  55.         if (!cool.isEmpty()){
  56.             for (String s : cool) {
  57.                 System.out.println(s);
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement