BetinaUKTC

PassExam

Feb 13th, 2021
1,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. import java.util.HashMap;
  2.  
  3. public class HackerRank_Main {
  4.    // static String str = "51Pa*0Lp*0e";
  5.  
  6.     static HashMap<Integer,Character> Numbers = new HashMap<>();
  7.     static HashMap<Integer,Character> LowS = new HashMap<>();
  8.     static HashMap<Integer,Character> UpperS = new HashMap<>();
  9.     static HashMap<Integer,Character> Low = new HashMap<>();
  10.     static HashMap<Integer,Character> Upper = new HashMap<>();
  11.  
  12.  
  13.     public static int findNums(String str) {
  14.         int numbers = 0;
  15.         for (int i = 1; i < str.length(); i++) {
  16.             if (str.charAt(i) == '0') {
  17.                 numbers++;
  18.             }
  19.         }
  20.         return numbers;
  21.     }
  22.  
  23.     public static void findIndex(String str) {
  24.         int numCount = 1;
  25.         for (int i = 0; i < str.length(); i++) {
  26.             if (str.charAt(i) == '0') {
  27.                 Numbers.put(i,str.charAt(findNums(str)-numCount));
  28.                 numCount++;
  29.             }
  30.             if (str.charAt(i) == '*') {
  31.                 LowS.put(i-1,str.charAt(i-2));
  32.                 UpperS.put( i-2,str.charAt(i-1));
  33.             }
  34.         }
  35.         for (int i = 0; i < str.length(); i++) {
  36.             if (Character.isLowerCase(str.charAt(i)) && !LowS.containsKey(i)){
  37.                 Low.put( i,str.charAt(i));
  38.             }
  39.             if (Character.isUpperCase(str.charAt(i)) && !UpperS.containsKey(i)){
  40.                 Upper.put(i, str.charAt(i) );
  41.             }
  42.         }
  43.     }
  44.  
  45.     public static String Pass(String str) {
  46.         String result = "";
  47.         findIndex(str);
  48.         for (int i = findNums(str); i < str.length(); i++) {
  49.             if (Low.containsKey(i)){
  50.                 result+=Low.get(i);
  51.             }
  52.             if (LowS.containsKey(i)){
  53.                 result+=LowS.get(i);
  54.             }
  55.             if (Numbers.containsKey(i)){
  56.                 result+=Numbers.get(i);
  57.             }
  58.             if (Upper.containsKey(i)){
  59.                 result+=Upper.get(i);
  60.             }
  61.             if (UpperS.containsKey(i)){
  62.                 result+=UpperS.get(i);
  63.             }
  64.  
  65.         }
  66.  
  67.         return result;
  68.     }
  69.  
  70.     public static void main(String[] args) {
  71.         String str = "625sK00Ke*0";
  72.         System.out.println(Pass(str));
  73.     }
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment