Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Ex2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- Pattern regex = Pattern.compile("([:]{2}|[*]{2})(?<emoji>[A-Z][a-z]{2,})(\\1)");
- Pattern regex1 = Pattern.compile("[\\d]");
- Matcher matcher = regex.matcher(input);
- Matcher matcher1 = regex1.matcher(input);
- long coolThreshold = 1;
- while (matcher1.find()){
- int digits = Integer.parseInt(matcher1.group(0));
- coolThreshold *= digits;
- }
- System.out.printf("Cool threshold: %d%n", coolThreshold);
- List<String> cool = new ArrayList<>();
- int coolness = 0;
- int count = 0;
- while (matcher.find()){
- String emoji = matcher.group("emoji");
- String group1 = matcher.group(1);
- coolness = 0;
- count++;
- for (int i = 0; i < emoji.length() ; i++) {
- char letter = emoji.charAt(i);
- coolness += letter;
- }
- if (coolness > coolThreshold){
- cool.add(group1 + emoji + group1);
- }
- // System.out.println(emoji);
- }
- System.out.printf("%d emojis found in the text. The cool ones are:%n", count);
- if (!cool.isEmpty()){
- for (String s : cool) {
- System.out.println(s);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement