Parcourir la source

分数加法,模拟,最大公约数

zj il y a 5 ans
Parent
commit
ba030045f1
1 fichiers modifiés avec 17 ajouts et 0 suppressions
  1. 17 0
      D.cpp

+ 17 - 0
D.cpp

@@ -0,0 +1,17 @@
+#include<bits/stdc++.h>
+
+using namespace std;
+
+int main() {
+    int T;
+    cin >> T;
+    while (T--) {
+        int a, b, c, d;
+        cin >> a >> b >> c >> d;
+        int e = a * d + b * c, f = b * d;
+        int g = __gcd(e, f);
+        e /= g, f /= g;
+        cout << e << " " << f << endl;
+    }
+    return 0;
+}