-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
161 lines (138 loc) · 4.05 KB
/
main.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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <iostream>
#include "BigInteger.hpp"
using namespace std;
int main() {
BigInteger a(-9999);
BigInteger b("5");
cout << b - a << '\n';
// BigInteger c("-123456");
// cin >> c;
// b /= c;
// a = a / c;
// Rational r(5);
// cout << r << '\n';
// cout << a + b << '\n';
// cout << b/3 << '\n';
/*
int p = 10;
Rational r1(2, 6);
Rational r2(1, 3);
Rational r3;
Rational r4(-0);
Rational r5(-10);
BigInteger b1("2");
BigInteger b2("3");
Rational r6(b1,b2);
cout << "r4 = " << '\t';
cout << r4.toString() <<'\t';
cout << r4.asDecimal(p) <<'\n';
cout << "r5 = " << '\t';
cout << r5.toString() <<'\t';
cout << r5.asDecimal(p) <<'\n';
cout << "r6 = " << '\t';
cout << r6.toString() <<'\t';
cout << r6.asDecimal(p) <<'\n';
cout << "-r1 = " << '\t';
cout << (-r1).toString() <<'\t';
cout << (-r1).asDecimal(p) <<'\n';
cout << "-r2 = " << '\t';
cout << (-r2).toString() <<'\t';
cout << (-r2).asDecimal(p) <<'\n';
r3 = r1 + r2;
cout << "r1 + r2 = " << '\t';
cout << r3.toString() <<'\t';
cout << r3.asDecimal(p) <<'\n';
r3 = r2 + r1;
cout << "r2 + r1 = " << '\t';
cout << r3.toString() <<'\t';
cout << r3.asDecimal(p) <<'\n';
r3 = r1 - r2;
cout << "r1 - r2 = " << '\t';
cout << r3.toString() <<'\t';
cout << r3.asDecimal(p) <<'\n';
r3 = r2 - r1;
cout << "r2 - r1 = " << '\t';
cout << r3.toString() <<'\t';
cout << r3.asDecimal(p) <<'\n';
r3 = r1 * r2;
cout << "r1 * r2 = " << '\t';
cout << r3.toString() <<'\t';
cout << r3.asDecimal(p) <<'\n';
r3 = r2 * r1;
cout << "r2 * r1 = " << '\t';
cout << r3.toString() <<'\t';
cout << r3.asDecimal(p) <<'\n';
r3 = r1 / r2;
cout << "r1 / r2 = " << '\t';
cout << r3.toString() <<'\t';
cout << r3.asDecimal(p) <<'\n';
r3 = r2 / r1;
cout << "r2 / r1 = " << '\t';
cout << r3.toString() <<'\t';
cout << r3.asDecimal(p) <<'\n';
cout << "r1 == r2 = " << '\t';
cout << (r1 == r2) <<'\n';
cout << "r2 == r1 = " << '\t';
cout << (r2 == r1) <<'\n';
cout << "r1 != r2 = " << '\t';
cout << (r1 != r2) <<'\n';
cout << "r2 != r1 = " << '\t';
cout << (r2 != r1) <<'\n';
cout << "r1 < r2 = " << '\t';
cout << (r1 < r2) <<'\n';
cout << "r2 < r1 = " << '\t';
cout << (r2 < r1) <<'\n';
cout << "r1 > r2 = " << '\t';
cout << (r1 > r2) <<'\n';
cout << "r2 > r1 = " << '\t';
cout << (r2 > r1) <<'\n';
cout << "r1 <= r2 = " << '\t';
cout << (r1 <= r2) <<'\n';
cout << "r2 <= r1 = " << '\t';
cout << (r2 <= r1) <<'\n';
cout << "r1 >= r2 = " << '\t';
cout << (r1 >= r2) <<'\n';
cout << "r2 >= r1 = " << '\t';
cout << (r2 >= r1) <<'\n';
cout << "(double)r1 = " <<'\t';
cout << (double)r1 << '\n';
cout << "(double)r2 = " <<'\t';
cout << (double)r2 << '\n';
// for (BigInteger i = 0; i < 100; ++i) {
Rational r7(0, -100);
Rational r(1, -100);
// r /= r7;
cout << r7.toString() << '\t' << r7.asDecimal(10) << '\n';
cout << r.toString() << '\t' << r.asDecimal(10) << '\n';
cout << (r7+r).toString() << '\t' << (r7+r).asDecimal(10) << '\n';
cout << (-r < r7 + r) <<'\n'; // -1/100 < 0 + -1/100 = -1/100
cout << ((Rational)0 > r7) <<'\n';
*/
// }
// cout << Rational("9999999", 123456).asDecimal(100) <<'\n';
// r2 = r1;
// cout << r2.toString() <<'\n';
// (r2 *= r1);
// r2.print();
// cout << r2.toString() <<'\n';
// cout << r2.asDecimal(3);
// vector<Rational> v;
// for (int i = 0; i < 100; ++i) {
// v.push_back(Rational(1, 100));
// }
// Rational result = 0;
// for (int i = 0; i < 99; ++i) {
// result += v[i];
// }
// cout << result.toString() << '\t' << result.asDecimal(10) << '\n';
//
// result += v[99];
// cout << result.toString() << '\t' << result.asDecimal(10) << '\n';
//
// BigInteger s1(9900);
// BigInteger s2(100);
// cout << s2 + s1 <<'\n';
Rational r(2, 100);
cout << r.asDecimal(4);
return 0;
}