Advertisement
it4l0

planeta

Dec 4th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. int main()
  2. {
  3.     int x = 0, z = 0, t = 0, aux = 0;
  4.     double tempo[100]; double aux1 = 0; double maior; int sistema[100]; int intmaior1;
  5.     scanf("%d", &x);
  6.     for (t = 0; t < x; ++t)
  7.     {
  8.         scanf("%lf", &tempo[t]);
  9.     }
  10.     //ordenacao de array
  11.     for (t = 0; t < x; ++t)
  12.     {
  13.         aux = t;
  14.         for (z = t + 1; z < x; ++z)
  15.         {
  16.             if(tempo[z] > tempo[aux])
  17.             {
  18.                 aux = z;
  19.             }
  20.         }
  21.         aux1 = tempo[t];
  22.         tempo[t] = tempo[aux];
  23.         tempo[aux] = aux1;
  24.     }
  25.     //fim ordenacao
  26.     for (t = 0; t < x; ++t)
  27.     {
  28.         sistema[t] = tempo[t] * 10;
  29.     }
  30.     maior = tempo[0];
  31.     int cont = x - 1, contador = 0; double maior1 = 0;
  32.     maior1 = maior; intmaior1 = maior1;
  33.     while(cont > 0)
  34.     {
  35.         for(t = 1; t < x; ++t)
  36.         {
  37.             if(sistema[t] == 0)
  38.             {
  39.                 printf("SEM RESPOSTA");
  40.             }
  41.             else if(intmaior1 % sistema[t] == 0)
  42.             {
  43.                 contador++;
  44.             }
  45.         }
  46.         if(contador == cont)
  47.         {
  48.             maior1 = intmaior1;
  49.             printf("O tempo para o alinhamento dos planetas e %.1lf minutos", maior1);
  50.             return 0;
  51.         } else{
  52.             intmaior1 += maior;
  53.             t = 1; contador = 0;
  54.         }
  55.     }
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement