Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
被阴,哈哈,整除情况#include <stdio.h> #include <stdlib.h> int maxPri(int a,int b) { int r=0; if(a<b) { a=a+b; b=a-b; a=a-b; } while(a%b!=0) { r=a%b; a=b; b=r; } return b; } int minPri(int a,int b)//求最小公倍数 { int r=0; int ab=a*b; return ab/maxPri(a,b); } int main() { int a,b,c,d; char op; int Bs=0; while(scanf("%d/%d%c%d/%d",&a,&b,&op,&c,&d)!=EOF) { Bs=minPri(b,d); a*=(Bs/b); c*=(Bs/d); if(op=='+') a=a+c; else a=a-c; if(a==0) printf("0\n"); else { int Ys=maxPri(abs(a),Bs); printf("%d",a/Ys); if(Ys!=Bs) { printf("/%d",Bs/Ys); } printf("\n"); } } system("pause"); return 1; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator