Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class emoji {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int threshold = 1;
- int countOfEmojis = 0;
- String input = scanner.nextLine();
- ArrayList<String> emojis = new ArrayList<>();
- String regexNumbers = "(\\d)";
- Pattern pattern = Pattern.compile(regexNumbers);
- Matcher matcherDigit = pattern.matcher(input);
- while (matcherDigit.find()) {
- int digit = Integer.parseInt(matcherDigit.group());
- threshold = threshold * digit;
- }
- String regexEmoji = "([:|\\*]{2})([A-Z][a-z]{2,})(\\1)";
- Pattern patternEmoji = Pattern.compile(regexEmoji);
- Matcher matcherEmoji = patternEmoji.matcher(input);
- while (matcherEmoji.find()) {
- int sumOfEmoji = 0;
- countOfEmojis++;
- String emoji = matcherEmoji.group();
- String testEmoji = matcherEmoji.group(2);
- for (int i = 0; i < testEmoji.length(); i++) {
- int value = (int) testEmoji.charAt(i);
- sumOfEmoji += value;
- }
- if (sumOfEmoji > threshold) {
- emojis.add(emoji);
- }
- }
- // if (emojis.size()>0) {
- System.out.println("Cool threshold: " + threshold);
- System.out.println(countOfEmojis + " emojis found in the text. The cool ones are:");
- if (emojis.size() > 0) {
- for (int i = 0; i < emojis.size(); i++) {
- System.out.printf("%s%n", emojis.get(i));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement