Skip to content

Instantly share code, notes, and snippets.

@folivetti
Created March 6, 2017 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save folivetti/d74aac8df04a6779d1306bfb41a80d5e to your computer and use it in GitHub Desktop.
Save folivetti/d74aac8df04a6779d1306bfb41a80d5e to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static int inverso(int x) {
int y = 0;
while (x!=0) {
y = y*10 + x%10;
x = x/10;
}
return y;
}
public static boolean palindrome(int x) {
while(x%10 == 0) x/=10;
return inverso(x) == x;
}
public static void main(String[] args) throws IOException {
double R;
int soma, inteiro, decimais;
int C, casas, mult, j;
Scanner leitor = new Scanner(System.in);
C = leitor.nextInt();
for (int i=0; i<C; i++) {
R = leitor.nextDouble();
inteiro = (int)R;
//R = R - (int)R;
mult = 1;
while ( (R - (int)R) != 0 ){
R = R*10;
mult = mult*10;
}
decimais = (int)R - inteiro*mult;
soma = inverso(inteiro) - decimais;
if (soma >= 0)
System.out.println(soma/(double)mult);
else
System.out.println(1./(double)mult);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment