AbhishekB
BAN USERCSCOMS.java
-----------------------------
public class CSCOMS {
private Set<String> stringSet;
public CSCOMS(String dictionary[]){
stringSet = new HashSet<String>();
for(int i = 0; i < dictionary.length; i++){
stringSet.add(dictionary[i]);
}
}
public boolean checkIfComposedOfMultipleString(String entry){
if(entry.length() == 0){
return true;
}
boolean result = false;
for(int i = 0; i < entry.length(); i++){
String token = entry.substring(0, i + 1);
if(stringSet.contains(token)){
result = checkIfComposedOfMultipleString(entry.substring(i + 1));
}
if(result){
break;
}
}
return result;
}
}
App.java
-----------------------------
public class App
{
public static void main( String[] args ){
String dictionary[] = {"world", "hello", "super", "hell"};
CSCOMS cscoms = new CSCOMS(dictionary);
String values[] = {"helloworld", "superman", "hellohello", "superhell", "hellsuper"};
System.out.print("Dictionary contents: ");
for(int i = 0; i < dictionary.length; i++){
System.out.print(dictionary[i] + " ");
}
System.out.println();
for(int i = 0; i < values.length; i++) {
System.out.println("\"" + values[i] + "\" --> " + cscoms.checkIfComposedOfMultipleString(values[i]));
}
}
}
CSCOMS.java
-----------------------------
App.java
-----------------------------
- AbhishekB October 31, 2014