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 superyoi at 2011-04-14 21:52:47 on Problem 3979
#include <stdio.h>
#include <math.h>

int a,b,c,d,x,y,i;
char fu;

int main()
{
    while (scanf("%d/%d%c%d/%d",&a,&b,&fu,&c,&d)!=EOF)
    {
        if (fu=='-') c=-c;
        y=b*d;
        x=a*d+b*c;
        i=2;
        while (i<=(int)fabs((double)x) && i<=y) 
            if (x%i==0 && y%i==0)
            {
                x/=i;
                y/=i;
            }
            else i++;          
        if (x==0 || y==1) printf("%d\n",x); else printf("%d/%d\n",x,y);
    }
    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