Advertisement
i_graurov

Emoji

Apr 4th, 2020
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class emoji {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int threshold = 1;
  10. int countOfEmojis = 0;
  11. String input = scanner.nextLine();
  12. ArrayList<String> emojis = new ArrayList<>();
  13.  
  14. String regexNumbers = "(\\d)";
  15. Pattern pattern = Pattern.compile(regexNumbers);
  16. Matcher matcherDigit = pattern.matcher(input);
  17. while (matcherDigit.find()) {
  18. int digit = Integer.parseInt(matcherDigit.group());
  19. threshold = threshold * digit;
  20. }
  21. String regexEmoji = "([:|\\*]{2})([A-Z][a-z]{2,})(\\1)";
  22. Pattern patternEmoji = Pattern.compile(regexEmoji);
  23. Matcher matcherEmoji = patternEmoji.matcher(input);
  24. while (matcherEmoji.find()) {
  25. int sumOfEmoji = 0;
  26. countOfEmojis++;
  27. String emoji = matcherEmoji.group();
  28. String testEmoji = matcherEmoji.group(2);
  29. for (int i = 0; i < testEmoji.length(); i++) {
  30. int value = (int) testEmoji.charAt(i);
  31. sumOfEmoji += value;
  32. }
  33. if (sumOfEmoji > threshold) {
  34. emojis.add(emoji);
  35. }
  36. }
  37. // if (emojis.size()>0) {
  38. System.out.println("Cool threshold: " + threshold);
  39. System.out.println(countOfEmojis + " emojis found in the text. The cool ones are:");
  40. if (emojis.size() > 0) {
  41. for (int i = 0; i < emojis.size(); i++) {
  42. System.out.printf("%s%n", emojis.get(i));
  43.  
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement