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

这。。一直wrong answer怎么破、。。

Posted by BD777 at 2012-11-18 09:41:28 on Problem 3979
#include<iostream>

using namespace std;

int max(int x,int y)
{
    return (x>y?x:y);
}

int ab(int x)
{
    if(x<0) return -x;
    else return x;
}

int yue(int x,int y)
{
    int t;
    if(x < y) {t=x;x=y;y=t;}
    if(y==0) return x;
    int k = x % y;
    yue(y,k);
}

int bei(int x,int y)
{
    int i;
    for(i=max(x,y);;i++)
        if(i%x==0 && i%y==0) return i;
}

int main()
{
    int a,b,c,d,e;
    char m,n;
    while(cin >> a >> n >> b >> m >> c >> n >> d)
    {
        int l=bei(b,d);
        a*=(l/b);
        c*=(l/d);
        if(m=='+') e=a+c;
        else e=a-c;
        if(e==0) {cout << 0 << endl;continue;}
        int p=yue(ab(e),l);
        e/=p;
        l/=p;
        if(l==1) cout << e << endl;
        else cout << e << "/" << l << endl;
    }
    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