Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CrossBitFixFree {
- public static void riempiMatrice(int[][] in, int col, int rows, int card){
- int range = card - 2 + 1;
- for(int i=0; i<col; i++){
- for(int j=0; j<rows; j++){
- in[j][i] = (int)(range*Math.random())+2;
- }
- }
- }
- public static void estraiSottoVettore(int[][] matr, int[] vet, int inizio, int fine, int riga){
- int k=0;
- for (int i=inizio; i<=fine; i++){
- vet[k] = matr[riga][i];
- k++;
- }
- }
- public static boolean sonoUguali(int[]a, int[]b){
- boolean ris = true;
- for (int i=0; i<a.length; i++){
- if(a[i]!=b[i]){
- ris = false;
- break;
- }
- }
- return ris;
- }
- public static void stampaMatrice(int[][] mat, int rows){
- for(int i=0; i<rows; i++){
- int l = mat[i].length;
- for(int j=0; j<l; j++){
- System.out.print(mat[i][j]+" ");
- }
- System.out.println();
- }
- System.out.println();
- }
- public static void stampaVettore(int[] a){
- for(int i=0; i<a.length; i++){
- System.out.print(a[i]+" ");
- }
- }
- public static void main(String[] args) {
- int q = 9; // cardinalità alfabeto
- int n = 5; // lunghezza parole (numero di colonne)
- int m = 5; // numero di parole (numero di righe)
- int[][] cross = new int[m][n];
- riempiMatrice(cross, n, m, q);
- for (int i=0; i<=n/2; i++){ // i = lunghezza dei suffissi e dei prefissi
- int[] pref = new int[i+1];
- int[] suff = new int[i+1];
- for(int j=0; j<m; j++){ // j = scorre i prefissi
- estraiSottoVettore(cross, pref, 0, i, j); //ESTRAE IL PREFISSO
- for(int k=0; k<m; k++){
- estraiSottoVettore(cross, suff, cross[k].length-1-i , cross[k].length-1, k); // ESTR
- if(sonoUguali(pref, suff)){
- System.out.println("\nL'insieme non è bifixfree");
- System.exit(0);
- }
- }
- }
- }
- System.out.println("\n\nL'insieme è bifixfree");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement