-
Notifications
You must be signed in to change notification settings - Fork 2
/
cancel.cpp
49 lines (43 loc) · 1003 Bytes
/
cancel.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
#include <cstdio>
using namespace std;
int simplify(int a,int b){//a/b
int temp;
while(a>0){
temp = b%a;
b = a;
a = temp;
}
return b;
}
int main(){
int TOP = 1;
int BOT = 1;
for(int bot = 10;bot<100;bot++){
for(int top = 10;top<bot;top++){
int a = bot%10;//bot ba
int b = bot/10;
int c = top%10;//top dc
int d = top/10;
if(a==0||b==0||c==0||d==0) continue;
if(a==c&&d*bot==b*top){
TOP*=d;
BOT*=b;
}
else if(a==d&&c*bot==b*top){
TOP*=c;
BOT*=b;
}
else if(b==c&&d*bot==a*top){
TOP*=d;
BOT*=a;
}
else if(b==d&&c*bot==a*top){
TOP*=c;
BOT*=a;
}
}
}
printf("%d %d\n",TOP,BOT);
printf("%d\n",BOT/simplify(TOP,BOT));
return 0;
}