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

所有的数据都对,为何WA????

Posted by sun152121 at 2011-02-13 11:18:49 on Problem 3979
#include<iostream>
using namespace std;
struct FS
{
	int fz;
	int fm;
};

int gcd(int a, int b)
{
     if(a<b) {
            int temp=a;
            a=b;
            b=temp;
     }
     if(b==0) return a;
           else return gcd(b,a%b);
}

int main()
{
	int a,b;
	int c,d;
	char ch1,ch2,ch;
	int g;
	while(cin>>a>>ch1>>b>>ch>>c>>ch2>>d)
	{
		FS fs1;
		FS fs2;
		FS fs;
		fs1.fz=a;
		fs1.fm=b;
		fs2.fz=c;
		fs2.fm=d;
		switch(ch)
		{
		case'+':
			{
				fs.fz=fs1.fz*fs2.fm+fs1.fm*fs2.fz;
				fs.fm=fs1.fm*fs2.fm;
				break;
			}
		default:
			{
				fs.fz=fs1.fz*fs2.fm-fs1.fm*fs2.fz;
				fs.fm=fs1.fm*fs2.fm;
				break;
			}
		}
		
		if(!fs.fz)
		{
			cout<<fs.fz/fs.fm<<endl;
		}
		if(fs.fz!=fs.fm && fs.fz>0)
		{
			g=gcd(fs.fz,fs.fm);
			fs.fz/=g;
			fs.fm/=g;
			cout<<fs.fz<<"/"<<fs.fm<<endl;
		}
		if(fs.fz!=fs.fm && fs.fz<0)
		{
			g=gcd(-fs.fz,fs.fm);
			fs.fz/=g;
			fs.fm/=g;
			cout<<fs.fz<<"/"<<fs.fm<<endl;
		}
		if(fs.fz==fs.fm)
		{
			cout<<fs.fz/fs.fm<<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