-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1034.cpp
More file actions
126 lines (121 loc) · 1.88 KB
/
1034.cpp
File metadata and controls
126 lines (121 loc) · 1.88 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include<iostream>
#include<cstdio>
using namespace std;
long long int gcd(long long int t1, long long int t2){
return t2 == 0 ? t1 : gcd(t2,t1%t2);
}
void func(long long int m,long long int n){
int flag1=0,flag2=0;
if(n==0){
cout<<"Inf";
return ;
}
if(m==0){
cout<<0;
return ;
}
if(m<0){
m = 0-m;
flag1=1;
}
if(n<0){
n=0-n;
flag2=1;
}
int flag=0;
if(flag1==1&&flag2==1){
flag=0;
}else if(flag1==1||flag2==1){
flag=1;
}
if(m==n){
if(flag==1)
cout<<"(-1)";
else
cout << "1";
return ;
}
long long int x=m%n;
long long int y=m/n;
if(x==0){
if(flag==0)
cout<<y;
else
cout<<"(-"<<y<<")";
return ;
}
else{
long long int t1=x;
long long int t2=n;
long long int t=gcd(t1,t2);
t1 = t1/t;t2=t2/t;
if(flag==1){
cout<<"(-";
if(y!=0)
cout<<y<<" "<<t1<<"/"<<t2;
else
cout<<t1<<"/"<<t2;
cout<<")";
}
else{
if(y!=0)
cout<<y<<" "<<t1<<"/"<<t2;
else
cout<<t1<<"/"<<t2;
}
}
}
void add(long long int a,long long int b,long long int c,long long int d){
long long int m,n;
m=a*d+b*c;
n=b*d;
func(a,b);
cout<<" + ";
func(c,d);
cout<<" = ";
func(m,n);
cout << endl;
}
void min(long long int a,long long int b,long long int c,long long int d){
long long int m,n;
m=a*d-b*c;
n=b*d;
func(a,b);
cout<<" - ";
func(c,d);
cout<<" = ";
func(m,n);
cout << endl;
}
void multi(long long int a,long long int b,long long int c,long long int d){
long long int m,n;
m=a*c;
n=b*d;
func(a,b);
cout<<" * ";
func(c,d);
cout<<" = ";
func(m,n);
cout << endl;
}
void div(long long int a,long long int b,long long int c,long long int d){
long long int m,n;
m=a*d;
n=b*c;
func(a,b);
cout<<" / ";
func(c,d);
cout<<" = ";
func(m,n);
cout << endl;
}
int main(){
long long int a,b,c,d;
scanf("%lld/%lld %lld/%lld",&a,&b,&c,&d);
add(a,b,c,d);
min(a,b,c,d);
multi(a,b,c,d);
div(a,b,c,d);
system("pause");
return 0;
}