标签:style blog io ar color os sp for on
1/8+3/8 1/4-1/2 1/3-1/3
1/2 -1/4 0
#include<stdio.h> main() { int f1,f2,m1,m2,i; char y; while(scanf("%d/%d%c%d/%d",&f1,&m1,&y,&f2,&m2)!=EOF)<span style="white-space:pre"> </span>//避免字符向数字的转换,直接输入 { f1*=m2;<span style="white-space:pre"> </span>//通分 f2*=m1; m1*=m2; if(y=='-') f1-=f2; else f1+=f2; for(i=2;i<=9;) { if(f1%i==0&&m1%i==0) { f1/=i; m1/=i; } else i++; } if(f1==0||f1==m1||-f1==m1||m1==1) printf("%d\n",f1);<span style="white-space:pre"> </span>//结果输出时一定要注意考虑相关情况 else printf("%d/%d\n",f1,m1); } return 0; }
标签:style blog io ar color os sp for on
原文地址:http://blog.csdn.net/fwjynll/article/details/41646697