My code is as follows :
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int T;
cin >> T;
while (T--)
{
char Num[16];
for (int Idx = 0; Idx < 16; Idx++)
Num[Idx] = 0;
cin >> Num;
int L;
for (L = 0; Num[L] != '.' && L < 16; L++);
int Dec = 0;
if (L == 16)
{
cout << 1 << endl;
continue;
}
else
{
for (int Nxt = 1; Nxt <= 4; Nxt++)
{
int DigitVal;
char Char = Num[L + Nxt];
if (Char == '\0')
DigitVal = 0;
else
DigitVal = Char - '0';
Dec = Dec * 10 + DigitVal;
}
}
if (Dec == 0)
{
cout << 1 << endl;
continue;
}
int GCD = __gcd(10000, Dec);
cout << 10000 / GCD << endl;
}
return 0;
}
It uses string. We get the 4 digits after the decimal point.
I have tested it on the test cases in the other forums, they all work.
Don’t know why its still giving WA.
created
last reply
- 8
replies
- 986
views
- 2
users
- 1
link