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 ACM_Hohai at 2011-10-16 20:31:58 on Problem 3979
#include <stdio.h>
#include <stdlib.h>

int maxPri(int a,int b)
{
    int r=0;
    if(a<b)
    {
        a=a+b;
        b=a-b;
        a=a-b;
    }
    while(a%b!=0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return b;
}

int minPri(int a,int b)//求最小公倍数 
{
    int r=0;
    int ab=a*b;
    
    return ab/maxPri(a,b);
}


int main()
{
    int a,b,c,d;
    char op;
    int Bs=0;
    while(scanf("%d/%d%c%d/%d",&a,&b,&op,&c,&d)!=EOF)
    {
        Bs=minPri(b,d);
        a*=(Bs/b);
        c*=(Bs/d);
        if(op=='+')
            a=a+c;
        else
            a=a-c;
        if(a==0)
            printf("0\n");
        else
        {
            int Ys=maxPri(abs(a),Bs);
            printf("%d",a/Ys);
            if(Ys!=Bs)
            {
                printf("/%d",Bs/Ys);
            }
            printf("\n");
        }
    }
    system("pause");
    return 1;
}

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