Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- public class HackerRank_Main {
- // static String str = "51Pa*0Lp*0e";
- static HashMap<Integer,Character> Numbers = new HashMap<>();
- static HashMap<Integer,Character> LowS = new HashMap<>();
- static HashMap<Integer,Character> UpperS = new HashMap<>();
- static HashMap<Integer,Character> Low = new HashMap<>();
- static HashMap<Integer,Character> Upper = new HashMap<>();
- public static int findNums(String str) {
- int numbers = 0;
- for (int i = 1; i < str.length(); i++) {
- if (str.charAt(i) == '0') {
- numbers++;
- }
- }
- return numbers;
- }
- public static void findIndex(String str) {
- int numCount = 1;
- for (int i = 0; i < str.length(); i++) {
- if (str.charAt(i) == '0') {
- Numbers.put(i,str.charAt(findNums(str)-numCount));
- numCount++;
- }
- if (str.charAt(i) == '*') {
- LowS.put(i-1,str.charAt(i-2));
- UpperS.put( i-2,str.charAt(i-1));
- }
- }
- for (int i = 0; i < str.length(); i++) {
- if (Character.isLowerCase(str.charAt(i)) && !LowS.containsKey(i)){
- Low.put( i,str.charAt(i));
- }
- if (Character.isUpperCase(str.charAt(i)) && !UpperS.containsKey(i)){
- Upper.put(i, str.charAt(i) );
- }
- }
- }
- public static String Pass(String str) {
- String result = "";
- findIndex(str);
- for (int i = findNums(str); i < str.length(); i++) {
- if (Low.containsKey(i)){
- result+=Low.get(i);
- }
- if (LowS.containsKey(i)){
- result+=LowS.get(i);
- }
- if (Numbers.containsKey(i)){
- result+=Numbers.get(i);
- }
- if (Upper.containsKey(i)){
- result+=Upper.get(i);
- }
- if (UpperS.containsKey(i)){
- result+=UpperS.get(i);
- }
- }
- return result;
- }
- public static void main(String[] args) {
- String str = "625sK00Ke*0";
- System.out.println(Pass(str));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment