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

这个为什么不对呢? 谁能告诉我?3979 Problem A

Posted by 2826801 at 2010-11-26 01:45:05 and last updated at 2010-11-26 01:47:02
#include<stdio.h>
#include<math.h>

void main(){
	char s[7];
	scanf("%s",&s);
	int a=s[0]-48;
	int b=s[2]-48;
	int c=s[4]-48;
	int d=s[6]-48;
	if(a==0 && c==0){
		printf("%d\n",0);
		return;
	}
	if(a==0 && s[3]=='+'){
		printf("%d/%d\n",c,d);
		return;
	}
	if(a==0 && s[3]=='-')
	{
		printf("-%d/%d\n",c,d);
		return;
	}
	if(c==0){
		printf("%d/%d\n",a,b);
		return;
	}
	int sum=b*d;
	int count;
	if(s[3]=='+')
	{
		count=a*d+b*c;
	}
	else
	{
		count=a*d-b*c;
	}
	if(count==0)
	{
		printf("%d\n",0);
		return;
	}
	else
	{
		if(count%sum==0)
		{
			printf("%d\n",count/sum);
		}
		else
		{
			int sum1=abs(sum);
			int count1=abs(count);
			int change1=sum1,change2=count1;
			if(sum1<count1)
			{
				sum1=count1;
				count1=change1;
			}
			while(sum1%count1){
				int d=sum1%count1;
				sum1=count1;
				count1=d;
			}
			if( sum<0 || count<0)
			{
				printf("%c%d/%d\n",'-',change2/count1,change1/count1);
			}
			else
			{
				printf("%d/%d\n",change2/count1,change1/count1);
			}
		}
	}
}

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