Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

怎么会不过的?

Posted by qianwei at 2011-01-12 21:19:06 on Problem 3979 and last updated at 2011-01-12 21:23:38
#include <stdio.h>
#include <string.h>

int main()
{
    int a,b,c,d,adbc,bd;
    char o,xx;
    while(scanf("%d%c%d%c%d%c%d",&a,&xx,&b,&o,&c,&xx,&d)!=EOF)
    {
        if(o=='-')
        {
            if(a/b<c/d)printf("-");
            adbc=a*d-b*c;
        }else adbc=a*d+b*c;
        bd=b*d;

        for(int temp=2;temp<=81;temp++) if(adbc%temp==0 && bd%temp==0){adbc/=temp;bd/=temp;temp=2;}
        if(adbc<0)adbc*=-1;
        if(bd<0)bd*=-1;
        if(adbc==0) printf("0\n");
        else if(bd==1) printf("%d\n",adbc);
        else printf("%d/%d\n",adbc,bd);



    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator