Skip to content

Instantly share code, notes, and snippets.

@rogerioagjr
Created April 27, 2015 03:24
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 rogerioagjr/bcf264f16ce759b02ae3 to your computer and use it in GitHub Desktop.
Save rogerioagjr/bcf264f16ce759b02ae3 to your computer and use it in GitHub Desktop.
import java.io.*;
public class Main{
public static void main(String[] args)throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
int testes,tempo = 0,i;
long populacaoA, populacaoB;
double percentualA, percentualB;
String[] aux;
testes = Integer.parseInt(in.readLine());
for (i = 1 ; i <= testes; i++){
aux = in.readLine().split(" ");
populacaoA = Long.parseLong(aux[0]);
populacaoB = Long.parseLong(aux[1]);
percentualA = Double.parseDouble(aux[2]);
percentualB = Double.parseDouble(aux[3]);
while (populacaoA <= populacaoB){
populacaoA += (long) (populacaoA * (percentualA/100));
populacaoB += (long) (populacaoB * (percentualB/100));
tempo++;
if (tempo > 100)break;
}
if (tempo <= 100)out.write(tempo+" anos.\n");
if (tempo > 100)out.write("Mais de 1 seculo.\n");
tempo = 0;
}
out.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment