Solution for multunus puzzle
: http://www.multunus.com/careers#hiring-process-faq , http://puzzle.multunus.com/cloud/createMain.java
import java.util.Map;
import java.util.Scanner;
public class Main {
private String orginalString = "";
private String duplicateString = "";
private KeyValues keyvalues = null;
private Map<String,String> mp = null;
public static void main(String[] args) {
Main m = new Main();
m.getUserInput();
}
private void getUserInput() {
keyvalues = new KeyValues();
mp=keyvalues.getValueMap();
Scanner sc = new Scanner(System.in);
String name = sc.nextLine();
orginalString = name;
if(name.contains(" ")){
String []strSpace = name.split(" ");
for(String str : strSpace){
//System.out.println(str);
checkForZero(str);
}
}else{
checkForZero(name);
}
}
private void checkForZero(String stri) {
if(stri.contains("0")){
String [] strZero = stri.split("0");
for(String st : strZero){
//System.out.println(st);
checkRedd(st);
System.out.print("\t");
}
} else{
checkRedd(stri);
}
}
private void checkRedd(String st) {
int startpt =0;
String tempStr = st;
//System.out.println(tempStr.length());
int i = 1;
while(i < tempStr.length()){
//System.out.println(tempStr.charAt(i));
//System.out.println(tempStr.charAt(i-1)+"---"+tempStr.charAt(i));
if(tempStr.charAt(i-1) != tempStr.charAt(i)){
duplicateString = duplicateString + tempStr.substring(startpt,i);
//System.out.println(tempStr.substring(startpt,i));
System.out.print("#########"+mp.get(duplicateString));
startpt = i;
}
else{
duplicateString="";
}
i++;
}
System.out.print(" kate output "+mp.get(tempStr.substring(duplicateString.length(),tempStr.length())));
//System.out.println(orginalString.substring(duplicateString.length(),orginalString.length()));
}
}
KeyValues.java
import java.util.HashMap;
import java.util.Map;
/**
*
*/
/**
* @author Aromal *
*/
public class KeyValues {
private Map<String,String> valueMap = null;
public KeyValues(){
valueMap = new HashMap<String, String>();
addValues();
}
private void addValues() {
valueMap.put("2", "a");
valueMap.put("22", "b");
valueMap.put("222", "c");
valueMap.put("3", "d");
valueMap.put("33", "e");
valueMap.put("333", "f");
valueMap.put("4", "g");
valueMap.put("44", "h");
valueMap.put("444", "i");
valueMap.put("5", "j");
valueMap.put("55", "k");
valueMap.put("555", "l");
valueMap.put("6", "m");
valueMap.put("66", "n");
valueMap.put("666", "o");
valueMap.put("7", "p");
valueMap.put("77", "q");
valueMap.put("7777", "r");
valueMap.put("8", "s");
valueMap.put("88", "t");
valueMap.put("888", "u");
valueMap.put("9", "v");
valueMap.put("99", "w");
valueMap.put("999", "y");
valueMap.put("9999", "z");
}
public Map<String, String> getValueMap() {
return valueMap;
}
}
Thanks +aromal chandra and +joseph james ...
http://belazy.blog.com/
No comments:
Post a Comment
Your feedback may help others !!!