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

Re:居然忘记了输出后换行,贡献了3次W4次PE。。。。。

Posted by inkbest at 2011-03-02 22:30:12 on Problem 3979
In Reply To:居然忘记了输出后换行,贡献了3次W4次PE。。。。。 Posted by:inkbest at 2011-03-02 22:29:43
#include <iostream>
using namespace std;

int gcd(int m,int n)
{
	int r=m%n;
	while(r!=0)
	{
		m=n;
		n=r;
		r=m%n;
	}
	return n;
}
int main()
{
	int a,b,c,d;
	char z;
	while(scanf("%d/%d%c%d/%d",&a,&b,&z,&c,&d)!=EOF)
	{
		int q,w;
		q=a*d;w=c*b;

		if(z=='+')
		{
			a=q+w;
		}
		else 
		{
			a=q-w;
		}
		b=b*d;
		int p=abs(gcd(a,b));
		if(a==0)
			cout<<a<<endl;
		else 
		{
			if(b<0) {a=-a;b=-b;}
			a=a/p;b=b/p;
			if(b==1)
				cout<<a<<endl;
			else 
				cout<<a<<'/'<<b<<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