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:怎么会不过的?

Posted by zhanhb at 2011-04-07 11:28:29 on Problem 3979
In Reply To:怎么会不过的? Posted by:qianwei at 2011-01-12 21:19:06
#include<stdio.h>

int gcd(int x,int y){
	int t;
	if(!x)return y;
	while(y){
		t=x%y;
		x=y;
		y=t;
	}
	return x;
}
int main(){
	int a,b,c,d,x,y,t;
	char o;
	while(5==scanf("%d / %d %c %d / %d",&a,&b,&o,&c,&d)){
		y=b*d;
		switch(o){
		case'+':x=a*d+b*c;break;
		case'-':x=a*d-b*c;break;
		}
		t=gcd(x,y);
		x/=t;
		y/=t;
		if(y<0){
			y=-y;
			x=-x;
		}
		printf("%d",x);
		if(y!=1)printf("/%d",y);
		printf("\n");
	}
	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