-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleet_166.cpp
58 lines (56 loc) · 1008 Bytes
/
leet_166.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
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
using namespace std;
const int N=100001;
int n,m;
void swap(int & a, int & b){
int temp = a;
a = b;
b = temp;
}
int gcd(int a, int b){
if (a<b) {
swap(a,b);
}
// a >= b
while(a != 0 && b != 0){
a = a % b;
swap(a,b);
}
return a;
}
bool tens(int a){
while(a%2 == 0) a /= 2;
while(a%5 == 0) a /= 5;
return a == 1;
}
string fractionToDecimal(int numerator, int denominator) {
int g = gcd(numerator, denominator);
numerator /= g;
denominator /= g;
string s;
if (tens(denominator)){
s = to_string(double(numerator)/double(denominator));
if(s != "0"){
while(s[s.size()-1] == '0'){
s.erase(s.size()-1);
}
if(s[s.size()-1] == '.'){
s.erase(s.size()-1);
}
}
return s;
}
int ord = 1;
int nines = 9;
}
int main(void) {
int a,b;
scanf("%d%d", &a, &b);
cout << fractionToDecimal(a,b);
}