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 |
OLERT 一直是OLE,真心不懂,求解: #include <iostream> #include <cstdio> #include <string> #include <string.h> #include <map> #include <vector> #include <cstdlib> #include <cmath> #include <algorithm> #include <queue> #include <set> #include <stack> using namespace std; int ax, ay, fzb, fmb; char po; int gcd(int a, int b) { if(b==0) return a; else return gcd(b, a%b); } int main() { while(scanf("%d/%d%c%d/%d", &ax, &ay, &po, &fzb, &fmb)) { if(po == '-') { fzb *= -1; } int m = ay*fmb; int z1 = ax*fmb; int z2 = fzb*ay; int sum = z1+z2; int gy = gcd(sum, m); sum /= gy; m /= gy; if(sum == 0) printf("0\n"); else if(m==1 || m==-1) printf("%d\n", sum/m); else { if(m < 0 && sum > 0) { m = -m; sum = -sum; } printf("%d/%d\n", sum, m); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator