• + 0 comments

    Here's part of my code: It passed test case 0, but failed the other test cases. I am wondering where I am going wrong. Any suggestions? Thank you.

    include

    using namespace std; const long double PI = 3.141592653589793284626433832795028841971693993751; string ltrim(const string &); string rtrim(const string &); vector split(const string &);

    int main() { string first_multiple_input_temp; getline(cin, first_multiple_input_temp);

    vector<string> first_multiple_input = split(rtrim(first_multiple_input_temp));
    
    long min = stol(first_multiple_input[0]);
    
    long max = stol(first_multiple_input[1]);
    
    // Write your code here
    if(min > 0 && max > min)
    

    {
    long num, denom; double dist1, dist2, minD = PI; double n; //cout << PI << "\t" << to_string(PI) << endl;

    for(double  d  = min; d <= max; d++){
        n = 3 * d;
       // cout << n  << "\t" << d << "\t";
    

    dist1 = abs(((n / d) - PI)); //cout << static_cast ((n / d) )<< endl; n++; // cout << n << "\t" << d << endl; dist2 = abs(((n / d) - PI)); //cout << static_cast ((n / d) )<< endl; // cout << dist1 << '\t' << dist2 << endl; if(dist1 < dist2){ if(minD > dist1){ num = n; denom = d; minD = dist1; } } if(dist2 < dist1){ if(minD > dist2){ num = n; denom = d; minD = dist2; } }

    /* if(dist1 == minD || dist2 == minD){ num = n; denom = d;

    }*/
    //cout << minD << endl;
    
    }
    cout << num << "/"
    << denom << endl;
    

    } return 0; }