-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1022.cpp
50 lines (42 loc) · 1.1 KB
/
1022.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
/****************************************************************/
/* Author : Muzakkir Hossain Minhaz */
/* Github : github.com/MuzakkirHossainMinhaz */
/* Linkedin : linkedin.com/in/muzakkir-hossain-minhaz */
/****************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int a, b, c, d, x, y;
char op;
scanf("%d / %d %c %d / %d", &a, &b, &op, &c, &d);
switch(op)
{
case '+':
x = a*d + c*b;
y = b*d;
break;
case '-':
x = a*d - c*b;
y = b*d;
break;
case '*':
x = a*c;
y = b*d;
break;
case '/':
x = a*d;
y = b*c;
}
int multiplier=0;
for(int i=1; i<=abs(min(x, y)); i++)
if(x%i==0 && y%i==0)
multiplier = i;
printf("%d/%d = %d/%d\n", x, y, x/multiplier, y/multiplier);
}
return 0;
}