Advertisement
KDOXG

URI Online Judge | 1964

Mar 14th, 2020
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. /*
  2.  *  URI Online Judge | 1964
  3.  *  Author: Kaio KDOXG
  4.  *  Federal University of Pelotas, 2020
  5.  *
  6.  */
  7.  
  8. #include <stdio.h>
  9. #define A "Ana"
  10. #define B "Bia"
  11.  
  12. int main()
  13. {
  14.     unsigned long long Pa, Pb;          //A's and B's position
  15.     unsigned long long i, j;            //Iterators
  16.     unsigned long long choice;          //Final choice
  17.  
  18.     unsigned long long C;
  19.     unsigned long long Va, Vb;
  20.     unsigned long long T;
  21.     unsigned long long D;
  22.  
  23.     scanf("%llu%llu%llu%llu%llu", &C, &Va, &Vb, &T, &D);
  24.  
  25.     if (C == 0 || C > 1000)
  26.         return -1;
  27.     if (Va == 0 || Va > 400)
  28.         return -1;
  29.     if (Vb == 0 || Vb > 400)
  30.         return -1;
  31.     if (T > 200)
  32.         return -1;
  33.     if (D >= C)
  34.         return -1;
  35.  
  36.     C *= 100;                       //Meters to centimeters
  37.     D *= 100;
  38.     Pa = D; Pb = D;
  39.     T *= 60;                     //Minutes to seconds
  40.  
  41.     for (i=100; i<T; i++)
  42.     {
  43.         Pa += Va;
  44.         if (Pa >= C)
  45.             Pa -= C;
  46.         Pb += Vb;
  47.         if (Pb >= C)
  48.             Pb -= C;
  49.     }
  50.  
  51.     while (1)
  52.     {
  53.         Pa += Va;
  54.         Pb += Vb;
  55.         if (Pa >= C || Pb >= C)
  56.         {
  57.             choice = Pb > Pa ? 1 : 0;
  58.             break;
  59.         }
  60.     }
  61.  
  62.     switch(choice)
  63.     {
  64.         case 0:
  65.             printf("%s", A);
  66.             break;
  67.         case 1:
  68.             printf("%s", B);
  69.             break;
  70.         default:
  71.             return -1;
  72.     }
  73.  
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement