讨论 / 求简化·
renqiangii 2011-04-23 07:27:00
点我顶贴 收藏 删除
#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#define SIZE (int*)malloc(n*sizeof(int))

long gys(int *a,int *b)

{

int temp,*pt;

if(*a%*b==0)

return *b;

else

temp=*a%*b;

pt=&temp;

return gys(b,pt);

}

int gbs(int *a,int *b)

{

int gys(int *a,int *b);

int temp,i;

temp=gys(a,b);

return *a**b/temp;

}

main()

{

int *a1,*a2,*b1,*b2;

int *pa1,*pa2,*pb1,*pb2,*pc,*pf;

int n,i,j,gb,gy,cha,fs;

scanf("%d",&n);

a1=SIZE;

a2=SIZE;

b1=SIZE;

b2=SIZE;

pa1=a1;

pa2=a2;

pb1=b1;

pb2=b2;

for(i=0;i<n;i++)

scanf("%d/%d-%d/%d",&a1[i],&a2[i],&b1[i],&b2[i]);

int gys(int *a,int*b);

int gbs(int *a,int*b);

void shuchu(int cha,int gb);

for(j=0;j<n;j++)

{

gb=gbs(pa2+j,pb2+j);

a1[j]*=(gb/a2[j]);

b1[j]*=(gb/b2[j]);

cha=a1[j]-b1[j];

shuchu(cha,gb);}

free(a1);

free(a2);

free(b1);

free(b2);

system("pause");

}

void shuchu(int cha,int gb)

{

int ys,*pc,*pf;

if(abs(cha)==gb)

{

if (cha<0)printf("-1\n");

else printf("1\n");}

else

{

pc=&cha;

pf=&gb;

ys=abs(gys(pf,pc));

printf("%d/%d\n",cha/ys,gb/ys);

}

}

查看更多回复
提交回复