UVa 12970 Alcoholic Pilots
1
#include <stdio.h>
2 #include
<stdlib.h>
3 #include
<iostream>
4 #include
<algorithm>
5 using
namespace std;
6 long long
int gcd(long long int a,long long
int b)
7 {
8 return b?gcd(b,a%b):a;
9 }
10 int main()
11 {
12 long long int v1,d1,v2,d2,cas=1;
13 while(cin>>v1>>d1>>v2>>d2 && (v1!=0||v2!=0||d1!=0||d2!=0))
14 {
15 long long int a=d1*v2,b=d2*v1;
16 if(a<b) printf("Case #%lld: You owe me a beer!\n",cas++);
17 else if(a>b) printf("Case #%lld: No beer for the captain.\n",cas++);
18 long long int time=d1*v2+d2*v1,mo=v1*v2*2;
19 long long int div=gcd(time,mo);
20 long long int s=time/div,m=mo/div;
21 if(m==1) printf("Avg. arrival
time: %lld\n",s);
22 else printf("Avg. arrival
time: %lld/%lld\n",s,m);
23 }
24 return 0;
25 }
留言
張貼留言