here is only basic implementation of problems for beginners. If you have any problem with any solution or any basic concept of programming or you want more efficient solution you can mail me.
my suggestion is not to copy and paste codes from here try to understand the logic and think why you were not able to solve it.

Tuesday, 30 December 2014

Game of chocolate

problem statement is here


#include<stdio.h>
long long gcd(long long a,long long b){
    if(b==0){
        return a;
    }
return gcd(b,a%b);
}
int main(){
long long a,b,c,d,e,f,g,i,j,cc=1,t;
scanf("%lld",&t);
while(t--){
scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
e=a*(c+1)+b*(d+1);
        f=(a+b)*(c+1+d);
        g=gcd(e,f);
        if(g>0){
        e/=g;
        f/=g;
        }
        if(e==0){
        printf("Case %lld: 0\n",cc);
        }else{
        printf("Case %lld: %lld/%lld\n",cc,e,f);
        }
        cc++;
}
return 0;
}

No comments:

Post a Comment