-
Notifications
You must be signed in to change notification settings - Fork 1
/
hw2-2.cpp
50 lines (47 loc) · 802 Bytes
/
hw2-2.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
#include<cstdio>
class dif
{
private:
int a;
int b;
public:
dif(int _a = 1, int _b = 1):a(_a),b(_b){}
~dif(){}
dif operator* (const dif & _d)
{
return dif(a * _d.a, b * _d.b);
}
bool operator< (const dif & _d)
{
return a * _d.b < b * _d.a;
}
void print() const
{
printf("%d/%d\n",a,b);
}
};
const dif half(1,2);
const dif doub(2,1);
const dif form(2,3);
int main()
{
dif init(1,1);
for (int i = 0; i < 18; i++)
{
init = init * form;
if(init < half)
{
printf("rise\t");
}
else
{
printf("norise\t");
}
while (init < half)
{
init = init * doub;
}
init.print();
}
return 0;
}