Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Please help in SPOJ GAMES

$
0
0

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);
}

Viewing all articles
Browse latest Browse all 39796


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>