-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1022 - TDA Rational.cpp
51 lines (48 loc) · 1.25 KB
/
1022 - TDA Rational.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define nl cout << "\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
void solve()
{
int a,b,c,d;
char x,y,z;
cin >> a >> x >>b >> y >> c >>z >> d;
if(y=='+'){
int nu = a*d + b*c;
int de = b*d;
cout << nu << '/' << de << " = ";
int div = __gcd(abs(nu),abs(de));
cout << nu/div << '/' << de /div;
}
else if(y=='-'){
int nu = a*d - b*c;
int de = b*d;
cout << nu << '/' << de << " = ";
int div = __gcd(abs(nu),abs(de));
cout << nu/div << '/' << de /div;
}
else if(y=='*'){
int nu = a*c;
int de = b*d;
cout << nu << '/' << de << " = ";
int div = __gcd(abs(nu),abs(de));
cout << nu/div << '/' << de /div;
}
else if(y=='/'){
int nu = a*d;
int de = b*c;
cout << nu << '/' << de << " = ";
int div = __gcd(abs(nu),abs(de));
cout << nu/div << '/' << de /div;
}
nl;
}
int main()
{
fast;
int n;
cin >> n; while(n--){solve();}
}