Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package New;
- import org.w3c.dom.ls.LSOutput;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Test {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String string = scan.nextLine();
- Pattern pattern = Pattern.compile("([:*]{2})(?<emojy>[A-Z][a-z]{2,})(\\1)");
- Pattern numbers =Pattern.compile("[0-9]");
- Matcher patternMatcher = pattern.matcher(string);
- Matcher numbersMatcher = numbers.matcher(string);
- BigDecimal coolT = new BigDecimal(1);
- ArrayList<String> coolEm = new ArrayList<>();
- while (numbersMatcher.find()){
- int num = Integer.parseInt(numbersMatcher.group(0));
- coolT = coolT.multiply(BigDecimal.valueOf(num));
- }
- int emCounter = 0;
- while (patternMatcher.find()){
- String emojy = patternMatcher.group("emojy");
- BigDecimal coolness = new BigDecimal(0);
- Pattern letters = Pattern.compile("[A-Za-z]");
- Matcher letterMatcher = letters.matcher(emojy);
- while (letterMatcher.find()) {
- char value = letterMatcher.group(0).charAt(0);
- coolness = coolness.add(BigDecimal.valueOf(value));
- }
- if (coolness.compareTo(coolT)==0 || coolness.compareTo(coolT)==1){
- coolEm.add(patternMatcher.group(1) + patternMatcher.group("emojy") + patternMatcher.group(3));
- }
- emCounter++;
- }
- System.out.println("Cool threshold: " + coolT);
- System.out.println( emCounter + " emojis found in the text. The cool ones are:");
- for (String s : coolEm) {
- System.out.println(s );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement