Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- class Solution
- {
- public static void main(String args[])
- {
- Scanner in = new Scanner(System.in);
- String mode = in.nextLine();
- String s = in.nextLine();
- if(mode.indexOf("letters") != -1 && mode.indexOf("NONE") == -1)
- {
- String regex = "";
- regex += "[a-zA-Z]";
- s=s.replaceAll(regex,"");
- }
- if(mode.indexOf("numbers") != -1 && mode.indexOf("NONE") == -1)
- {
- String regex = "";
- regex += "[0-9]";
- s=s.replaceAll(regex,"");
- }
- if(mode.indexOf("symbols") != -1 && mode.indexOf("NONE") == -1)
- {
- String regex = "";
- regex += "[^a-zA-Z0-9]";
- s=s.replaceAll(regex,"");
- }
- int sum = 0;
- String taken = "";
- for(int i = 0; i< s.length(); i++)
- {
- char c = s.charAt(i);
- if(taken.indexOf(c) == -1)
- {
- sum += c;
- taken += c;
- }
- }
- System.out.printf("%s%n%d",s,sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement