Please help in SPOJ GAMES

Problem: http://www.spoj.com/problems/GAMES/ My solution is giving right answer for the test cases given in the question but i m still getting wrong answer. I am not able to find the bug, Any sort of Help will be appreciated, Thank You.

Code:

#include <iostream>
using namespace std;

// gcd algo
int gcd(int, int);

int main() {
    int t;
    cin >> t;
    while(t--) {
        string n; 
        cin >> n;
        string f_part;
        int count = 0,check = 0;
        for(int i = 0; i < n.length(); i++) {
            if(n[i] == '.') {
                check = 1;
                continue;
            }
            if(check == 1)
                count++;
            if(n[i] == '.') continue;
            else
                f_part += n[i];
        }
        int x = atoi(f_part.c_str());
        string deno = "1";
        while(count--) deno += '0';
        int deno_int = atoi(deno.c_str()); 
        int gcd2 = gcd(x, deno_int);
        cout << deno_int / gcd2 << endl;
    }
}

int gcd(int a, int b) {
    if(a % b == 0) return b;
    else return gcd(a, a % b);
}

Hey @wallcrawler

The problem in the code may lie in this line (int x = atoi(f_part.c_str()):wink:

The question states that your average can be less than 10^6 and upto 4 decimal places. Let’s take your average to be 999,999.9999. This number satisfies the criteria for the average but when you convert into to int using the atoi method, there is a case for integer overflow as int ranges from -2,147,483,648 to 2,147,483,647.

Hope this proves to be helpful.