a/b + c/d
Time Limit : 1000/1000ms (Java/Other)Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 181Accepted Submission(s) : 123
Font:Times New Roman|Verdana|Georgia
Font Size:←→
Problem Description
Input
Output
Sample Input
2 1 2 1 3 4 3 2 3
Sample Output
5 6 2 1
【解题思路】模拟题
#include <iostream> using namespace std; int up,down; int gcd(int a, int b) { for (; (a = a % b) && (b = b % a);); return (a | b); } void add(int a, int b, int c, int d) { if(b==d){ up = a+c; down = b; } else{ up = a*d+c*b; down = b*d; } int ggcd = gcd(up,down); up /= ggcd;down/=ggcd; } int main() { //freopen("test.txt","r",stdin); int n, a, b, c, d; cin >> n; while (n--) { cin >> a >> b >> c >> d; add(a,b,c,d); cout<<up<<" "<<down<<endl; } return 0; }