Created
November 23, 2009 18:34
-
-
Save dizzi/241263 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Ham { | |
| static int[][] matrix = null; | |
| static int dist = 2; | |
| public static void main(String[] args) { | |
| String sentence = "accbaccbcacadd"; | |
| String pattern = "acbc"; | |
| char[] senChars = sentence.toCharArray(); | |
| char[] patChars = pattern.toCharArray(); | |
| matrix= new int[senChars.length][patChars.length]; | |
| for(int x = 0; x<senChars.length; x++ ){ | |
| for(int y = 0; y<patChars.length; y++ ){ | |
| if(senChars[x]==patChars[y]){ | |
| matrix[x][y]=getPrev(x,y); | |
| }else{ | |
| matrix[x][y]=getPrev(x,y)+1; | |
| } | |
| // if(senChars[x]==patChars[y]){ | |
| // matrix[x][y]=getPrev(x,y); | |
| // }else{ | |
| // matrix[x][y]=getPrev(x,y)+1; | |
| // } | |
| } | |
| } | |
| for(int y = 0; y<patChars.length; y++ ){ | |
| for(int x = 0; x<senChars.length; x++ ){ | |
| System.out.print(matrix[x][y]+" "); | |
| } | |
| System.out.println(); | |
| } | |
| } | |
| static int getPrev(int x, int y){ | |
| if(y-1<0) | |
| return 0; | |
| if(x-1<0) | |
| return dist+1; | |
| else | |
| return matrix[x-1][y-1]; | |
| } | |
| // static int min(int x, int y, int z){ | |
| // int ret = 0; | |
| // if(x<y)ret = x; else ret = y; | |
| // if() | |
| // } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment