Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. unsigned long long gcd(long a, long b) {
  5. return b == 0 ? a : gcd(b, a % b);
  6. }
  7.  
  8. int main(int argc, const char * argv[]) {
  9.  
  10. unsigned long long v1,d1,v2,d2,iGcd,fTop,fBot,tL,tR;
  11. unsigned long long i = 1;
  12. while(cin >> v1 && v1 !=0){
  13.  
  14. cin >> d1 >> v2 >> d2;
  15.  
  16.  
  17. fTop = (d2*v1)+(d1*v2);
  18.  
  19. fBot = v1 * v2 * 2;
  20.  
  21. iGcd = gcd(fTop, fBot);
  22.  
  23. if(tR>tL){
  24. cout << "Case #" << i << ": You owe me a beer!" << endl;
  25. cout << "Avg. arrival time: " << (fTop/iGcd);
  26. if(iGcd != fBot){
  27. cout << "/" << (fBot/iGcd) << endl;
  28. }
  29. else{
  30. cout << endl;
  31. }
  32. }
  33. else {
  34. cout << "Case #" << i << ": No beer for the captain."<< endl;
  35. cout << "Avg. arrival time: " << (fTop/iGcd);
  36. if(iGcd != fBot){
  37. cout << "/" << (fBot/iGcd) << endl;
  38. }
  39. else{
  40. cout << endl;
  41. }
  42. }
  43.  
  44. i++;
  45. }
  46.  
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement