a.md.kamil
BAN USERclass Check {
public boolean checkIt(String[] dict, String str) {
int length = str.length();
int newLenth = 0;
for (int i = 0; i <= dict.length - 1; i++) {
while (true) {
if (str.contains(dict[i])) {
newLenth = newLenth + dict[i].length();
int value = str.indexOf(dict[i]);
if (value == 0) {
if (str.length() == dict[i].length()) {
str = "";
} else {
str = str.substring(dict[i].length(), str.length());
}
} else {
if (value + dict[i].length() >= length) {
str = str.substring(0, value);
} else {
str = str.substring(0, value)
+ str.substring(value + dict[i].length(),
str.length());
}
}
if (newLenth == length) {
return true;
}
} else {
break;
}
}
}
return false;
}
}
public class CheckKey {
public static void main(String[] args) {
Check check = new Check();
String[] dict = { "world", "hello", "super", "hell" };
System.out.println(check.checkIt(dict, "helloworld"));
}
}
- a.md.kamil November 19, 2014
}
- a.md.kamil November 19, 2014