Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.LinkedHashMap;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class EmojiDetector {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String text = scanner.nextLine();
- String regexValidWords = "(?<a>[:*]{2})(?<word>[A-Z][a-z]{2,})\\k<a>";
- String threshold = "[\\d]";
- Pattern pattern = Pattern.compile(threshold);
- Matcher matcher = pattern.matcher(text);
- long total = 1;
- while (matcher.find()) {
- int combine = Integer.parseInt(matcher.group());
- total *= combine;
- }
- ArrayList<String> coolList = new ArrayList<>();
- Pattern p = Pattern.compile(regexValidWords);
- Matcher m = p.matcher(text);
- int emojisInText = 0;
- while (m.find()) {
- String fullWordMatched = m.group();
- String matched = m.group("word");
- int sum = 0;
- for (int i = 0; i < matched.length(); i++) {
- char ascii = matched.charAt(i);
- sum += ascii;
- }
- if (sum > total) {
- coolList.add(fullWordMatched);
- }
- emojisInText++;
- }
- System.out.println(String.format("Cool threshold: %d", total));
- System.out.println(String.format("%d emojis found in the text. The cool ones are:", emojisInText));
- for (String s : coolList) {
- System.out.println(s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement