Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public void allPossibleWords(char C[][], int i, int j, int N, int M, char res[], int idx) {
  4.        
  5.         if (i > N || j > M) {
  6.             return;
  7.         }
  8.  
  9.         res[idx] = C[i][j];
  10.         for (int l = 0; l <= idx; l++) {
  11.             System.out.print(res[l]);
  12.         }
  13.         System.out.println();
  14.         allPossibleWords(C, i + 1, j, N, M, res, idx + 1);
  15.         allPossibleWords(C, i, j + 1, N, M, res, idx + 1);
  16.         allPossibleWords(C, i + 1, j + 1, N, M, res, idx + 1);      
  17.  
  18.     }
  19.  
  20.     public String[] findWords(String[] grid, String[] wordlist) {
  21.         char C[][] = new char[51][51];
  22.         for (int i = 0; i < grid.length; i++) {
  23.             for (int j = 0; j < grid[i].length(); j++) {
  24.                 C[i][j] = grid[i].charAt(j);
  25.             }
  26.         }
  27.         allPossibleWords(C, 0, 0, grid.length, grid[1].length(), new char[2001], 0);
  28.  
  29.         for (int i = 0; i < grid.length; i++) {
  30.             for (int j = 0; j < C[i].length; j++) {
  31.                 System.out.print(C[i][j] + " ");
  32.             }
  33.             System.out.println();
  34.         }
  35.         return null;
  36.     }
  37.  
  38.     public void run() {
  39.         findWords(new String[]{"TE",
  40.             "GO"}, new String[]{"", ""});
  41.     }
  42.  
  43.     public static void main(String[] args) {
  44.         new Main().run();
  45.     }
  46.  
  47.     class Node {
  48.  
  49.         char letter;
  50.         boolean fullWord;
  51.         Node child[];
  52.         String index = "";
  53.  
  54.         public Node(char letter) {
  55.             this.letter = letter;
  56.             child = new Node[26];
  57.             fullWord = false;
  58.         }
  59.  
  60.         public void insertWord(Node root, String word) {
  61.             int l = word.length();
  62.             Node curNode = root;
  63.             char c[] = word.toCharArray();
  64.             for (int i = 0; i < c.length; i++) {
  65.                 if (curNode.child[c[i] - 'A'] == null) {
  66.                     curNode.child[c[i] - 'A'] = new Node(c[i]);
  67.                 }
  68.                 curNode = curNode.child[c[i] - 'A'];
  69.             }
  70.             fullWord = true;
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement