-
Notifications
You must be signed in to change notification settings - Fork 0
/
14490.c
39 lines (36 loc) · 719 Bytes
/
14490.c
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
#include <stdio.h>
#include <string.h>
int main(){
char input[24];
int n,m,temp,tenten,idx;
int big,small;
scanf("%s",input);
n = m = 0;
tenten = 1;
idx = strlen(input) - 1;
while(input[idx] != ':'){
m += tenten * (input[idx] - '0');
tenten *= 10;
idx -= 1;
}
tenten = 1;
idx -= 1;
while(idx >= 0){
n += tenten * (input[idx] - '0');
tenten *= 10;
idx -= 1;
}
if(n > m){
big = n; small = m;
}
else{
big = m; small = n;
}
while(big % small != 0){
temp = big % small;
big = small;
small = temp;
}
printf("%d:%d\n",n/small,m/small);
return 0;
}