Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void printMatrice(int[][] matrix) {
- for (int i = 0; i < matrix.length; i++) {
- for (int j = 0; j < matrix[i].length; j++) {
- System.out.print(matrix[i][j] + " ");
- }
- System.out.println();
- }
- }
- void printArray(char [] x) {
- for (int i = 0; i < x.length; i++) {
- System.out.print(x[i] + " ");
- }
- System.out.println();
- }
- int[][] matrice() {
- int[][] m = new int[2][10];
- int contatore = 0;
- for (int i = 0; i < 10; i++) {
- m[0][i] = contatore;
- contatore++;
- m[1][i] = 0;
- }
- return m;
- }
- int[][] frequenzaNumero(long n) {
- int[][] x = matrice();
- long c = n;
- int contatore = 0;
- int indice = 0;
- while (indice < matrice()[0].length) {
- while (n > 0) {
- if (n % 10 == indice) {
- contatore = contatore + 1;
- }
- n = n / 10;
- }
- x[1][indice] = contatore;
- indice = indice + 1;
- n = c;
- contatore = 0;
- }
- return x;
- }
- int[][] ordinaMatrice(int[][] x) {
- int temp;
- int temp2;
- for (int i = 0; i < x[0].length; i++) {
- for (int j = i + 1; j < x[0].length; j++) {
- if (x[1][i] < x[1][j]) {
- temp = x[1][i];
- temp2 = x[0][i];
- x[1][i] = x[1][j];
- x[0][i] = x[0][j];
- x[1][j] = temp;
- x[0][j] = temp2;
- }
- }
- }
- return x;
- }
- //
- //char[] greedyCode(long n) {
- // int indice = 0 ;
- // char[] x = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
- // char[] ritorno = new char[x.length];
- // int[][] matrice = ordinaMatrice(frequenzaNumero(n));
- // while (indice <= 10) {
- // if (indice == matrice[1][indice]) {
- // ritorno[indice] = x[indice];
- // }
- // indice = indice = 1 ;
- // }
- //
- // return ritorno;
- //}
- printMatrice(frequenzaNumero(2136303418));
- System.out.println();
- //System.out.println(matrice()[0].length); // lunghezza rigo matrix .
- printMatrice(ordinaMatrice(frequenzaNumero(2136303418)));
- System.out.println();
- //System.out.println(greedyCode(2136303418));
- printArray(greedyCode(0));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement