Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1.  
  2. public class CrossBitFixFree {
  3.  
  4. public static void riempiMatrice(int[][] in, int col, int rows, int card){
  5.  
  6. int range = card - 2 + 1;
  7. for(int i=0; i<col; i++){
  8. for(int j=0; j<rows; j++){
  9. in[j][i] = (int)(range*Math.random())+2;
  10. }
  11. }
  12. }
  13.  
  14. public static void estraiSottoVettore(int[][] matr, int[] vet, int inizio, int fine, int riga){
  15. int k=0;
  16. for (int i=inizio; i<=fine; i++){
  17. vet[k] = matr[riga][i];
  18. k++;
  19. }
  20. }
  21.  
  22. public static boolean sonoUguali(int[]a, int[]b){
  23. boolean ris = true;
  24. for (int i=0; i<a.length; i++){
  25. if(a[i]!=b[i]){
  26. ris = false;
  27. break;
  28. }
  29. }
  30. return ris;
  31. }
  32.  
  33. public static void stampaMatrice(int[][] mat, int rows){
  34. for(int i=0; i<rows; i++){
  35. int l = mat[i].length;
  36. for(int j=0; j<l; j++){
  37. System.out.print(mat[i][j]+" ");
  38. }
  39. System.out.println();
  40. }
  41. System.out.println();
  42. }
  43.  
  44. public static void stampaVettore(int[] a){
  45. for(int i=0; i<a.length; i++){
  46. System.out.print(a[i]+" ");
  47. }
  48.  
  49. }
  50.  
  51.  
  52. public static void main(String[] args) {
  53.  
  54. int q = 9; // cardinalità alfabeto
  55. int n = 5; // lunghezza parole (numero di colonne)
  56. int m = 5; // numero di parole (numero di righe)
  57.  
  58. int[][] cross = new int[m][n];
  59. riempiMatrice(cross, n, m, q);
  60. for (int i=0; i<=n/2; i++){ // i = lunghezza dei suffissi e dei prefissi
  61. int[] pref = new int[i+1];
  62. int[] suff = new int[i+1];
  63. for(int j=0; j<m; j++){ // j = scorre i prefissi
  64. estraiSottoVettore(cross, pref, 0, i, j); //ESTRAE IL PREFISSO
  65. for(int k=0; k<m; k++){
  66. estraiSottoVettore(cross, suff, cross[k].length-1-i , cross[k].length-1, k); // ESTR
  67. if(sonoUguali(pref, suff)){
  68. System.out.println("\nL'insieme non è bifixfree");
  69. System.exit(0);
  70. }
  71. }
  72. }
  73. }
  74. System.out.println("\n\nL'insieme è bifixfree");
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement