Last active
August 29, 2015 14:23
-
-
Save NrI3/26d9cfefde4d30256470 to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// By Jsn | |
// | |
// Retorna un entero sin numeros duplicados | |
// tomando en cuenta la eliminacion de los digitos de izquierda a derecha | |
private static int limpiarDuplicados(int n){ | |
int x = n, nx = 0; | |
int y = 0, ny = 0; | |
int t = 0, c = 0,r = 0; | |
c = cantidadDigitos(n); | |
while ( x > 0 ){ | |
int e = (int)Math.pow(10,(c-1)); | |
c--; | |
nx = x / e ; | |
x %= e; | |
e /= 10; | |
r = r * 10 + nx; | |
y = x; | |
int a = e; | |
while ( y > 0 ){ | |
ny = y / a; | |
y %= a; | |
if ( nx != ny ){ | |
t = t * 10 + ny; | |
}else{ | |
c--; | |
} | |
a /= 10; | |
} | |
x = t; | |
t = 0; | |
} | |
System.out.println("Numbero: "+n); | |
System.out.println("Nro final: "+r); | |
return r; | |
} | |
// Retorna un entero sin numeros duplicados | |
// tomando en cuenta la eliminacion de los digitos derecha a izquierda | |
private static int limpiarDuplicadosInversamente(int o){ | |
int x = o, nx = 0; | |
int y = 0, ny = 0; | |
int t = 0, c = 0,r = 0; | |
while ( x > 0 ){ | |
nx = x % 10; | |
x /= 10; | |
r = nx * (int) Math.pow(10, c) + r; | |
c++; | |
y = x; | |
int a = 0; | |
while ( y > 0 ){ | |
ny = y % 10; | |
y /= 10; | |
if ( nx != ny ){ | |
t += (int) Math.pow(10,a) * ny; | |
a++; | |
} | |
} | |
x = t; | |
t = 0; | |
} | |
System.out.println("Numbero: "+o); | |
System.out.println("Nro final: "+r); | |
return r; | |
} | |
// Retorna la cantidad de digitos de un numero | |
private static int cantidadDigitos(int n){ | |
int c = 0; | |
while (n>0){ | |
c++; | |
n/=10; | |
} | |
return c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment