水题
#include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int T; int a,b,c,d; int gcd(int a,int b) { int t; while(b) { t = a%b; a = b; b = t; } return a; } int main() { scanf("%d",&T); while(T--) { scanf("%d%d%d%d",&a,&b,&c,&d); int x=a*d+b*c; int y=b*d; int z=gcd(x,y); printf("%d %d\n",x/z,y/z); } return 0; }
原文:http://www.cnblogs.com/zufezzt/p/4899320.html