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

OLE

Posted by lplp009 at 2013-08-17 22:43:14 on Problem 3979
RT 一直是OLE,真心不懂,求解:
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <map>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <stack>
using namespace std;
int ax, ay, fzb, fmb;
char po;
int gcd(int a, int b)
{
    if(b==0)
        return a;
    else
        return gcd(b, a%b);
}
int main()
{
    while(scanf("%d/%d%c%d/%d", &ax, &ay, &po, &fzb, &fmb))
    {
        if(po == '-')
        {
            fzb *= -1;
        }
        int m = ay*fmb;
        int z1 = ax*fmb;
        int z2 = fzb*ay;
        int sum = z1+z2;
        int gy = gcd(sum, m);
        sum /= gy;
        m /= gy;
        if(sum == 0)
            printf("0\n");
        else if(m==1 || m==-1)
            printf("%d\n", sum/m);
        else
        {
            if(m < 0 && sum > 0)
            {
                m = -m;
                sum = -sum;
            }
            printf("%d/%d\n", sum, m);
        }
    }
    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