Advertisement
roronoa

replace letters with, numbers with, symbols with

Apr 26th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4. class Solution
  5. {
  6.     public static void main(String args[])
  7.     {
  8.         Scanner in = new Scanner(System.in);
  9.         String mode = in.nextLine();
  10.         String s = in.nextLine();
  11.        
  12.         if(mode.indexOf("letters") != -1 && mode.indexOf("NONE") == -1)
  13.         {
  14.             String regex = "";
  15.             regex += "[a-zA-Z]";
  16.             s=s.replaceAll(regex,"");
  17.         }
  18.         if(mode.indexOf("numbers") != -1 && mode.indexOf("NONE") == -1)
  19.         {
  20.             String regex = "";
  21.             regex += "[0-9]";
  22.             s=s.replaceAll(regex,"");
  23.         }
  24.         if(mode.indexOf("symbols") != -1 && mode.indexOf("NONE") == -1)
  25.         {
  26.             String regex = "";
  27.             regex += "[^a-zA-Z0-9]";
  28.             s=s.replaceAll(regex,"");
  29.         }
  30.        
  31.         int sum = 0;
  32.         String taken = "";
  33.         for(int i = 0; i< s.length(); i++)
  34.         {
  35.             char c = s.charAt(i);
  36.             if(taken.indexOf(c) == -1)
  37.             {
  38.                 sum += c;
  39.                 taken += c;
  40.             }
  41.            
  42.         }
  43.         System.out.printf("%s%n%d",s,sum);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement