Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class d3 {
- public static void main(String[] args){
- String Search="loop";
- String[] letters = Search.split("") ;
- int counter;
- String[] words={"pole","pool","lopo","book","kobo"};
- for(int i=0;i<words.length;i++)
- {
- counter=0;
- String ssplit[] = words[i].split("");
- for(int j=0;j<words[i].length();j++)
- {
- if(letters.length==ssplit.length)
- {
- for(int k=0;k<letters.length;k++)
- {
- if(letters[j].equals(ssplit[k]))
- {counter++;
- ssplit[k]="*";
- break;
- }
- }
- if (counter == 4)
- {
- System.out.println(words[i]);
- }
- }
- }
- }
- }
- }
- public class d3 {
- public static void main(String[] args){
- String Search="loop";
- String[] letters = Search.split("") ;
- int counter;
- String[] words={"pole","pool","lopo","book","kobo"};
- for(int i=0;i<words.length;i++)
- {
- counter=0;
- String ssplit[] = words[i].split("");
- for(int j=0;j<words[i].length();j++)
- {
- if(letters.length==ssplit.length)
- {
- for(int k=0;k<letters.length;k++)
- {
- if(letters[j].equals(ssplit[k]))
- {
- counter++;
- ssplit[k]="*";
- break;
- }
- }
- if (counter == 4)
- {
- System.out.println(words[i]);
- }
- }
- }
- }
- }
- }
- for(int j=0;j<words[i].length();j++)
- {
- if(letters.length==ssplit.length)
- {
- ...
- }
- }
- if(letters.length==ssplit.length)
- {
- for(int j=0;j<ssplit.length;j++)
- {
- ...
- }
- }
- if(letters.length!=ssplit.length)
- {
- continue;
- }
- for(int j=0;j<ssplit.length;j++)
- {
- ...
- }
- if (counter == 4)
- {
- System.out.println(words[i]);
- }
- for(int j=0;j<words[i].length();j++)
- {
- for(int k=0;k<letters.length;k++)
- {
- if(letters[j].equals(ssplit[k]))
- {
- counter++;
- ssplit[k]="*";
- break;
- }
- }
- }
- class WordFinder {
- private final String[] words;
- WordFinder(String[] words) {
- this.words = new String[words.length];
- System.arraycopy(words, 0, this.words, 0, words.length);
- }
- String[] find(String word) {
- // Your code here
- }
- }
- String[] find(String word) {
- String[] result = new String[this.words.length];
- char[] letters = word.toCharArray();
- int counter = 0;
- for (String candidate : this.words) {
- if ( this.matches(letters, candidate.toCharArray()) ) {
- result[counter++] = candidate;
- }
- }
- return Arrays.copyOf(result, counter);
- }
- public class WordFinder {
- private final String[] words;
- public WordFinder(String[] words) {
- this.words = new String[words.length];
- System.arraycopy(words, 0, this.words, 0, words.length);
- }
- public String[] find(String word) {
- String[] result = new String[this.words.length];
- char[] letters = word.toCharArray();
- int counter = 0;
- for (String candidate : this.words) {
- if ( matches(letters, candidate.toCharArray()) ) {
- result[counter++] = candidate;
- }
- }
- return Arrays.copyOf(result, counter);
- }
- private boolean matches(char[] requirement, char[] candidate) {
- /* Edited to replace Arrays.hashCode with Arrays.equals, see comments
- return candidate.length==requirement.length &&
- hash(candidate)==hash(requirement);*/
- if ( candidate.length!=requirement.length ) {
- return false;
- }
- char left = Arrays.copyOf(requirement, requirement.length);
- Arrays.sort(left);
- char right = Arrays.copyOf(candidate, candidate.length);
- Arrays.sort(right );
- return Arrays.equals(left, right);
- }
- /*private int hash(char[] array) {
- char[] copy = Arrays.copyOf(array, array.length);
- Arrays.sort(copy);
- return Arrays.hashCode(copy);
- }*/
- }
Add Comment
Please, Sign In to add comment