• + 0 comments

    Here's an update on where I am at on this challenge: I now got it to 15.00 points with test cases 0 - 10 passed of the 50 ones. Any suggestions please?

    include

    using namespace std; const long double PI = 3.1415926535897932384626433832795028841971693993751; 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; long n; //cout << PI << "\t" << to_string(PI) << endl;

    for(double  d  = min; d <= max; d++){
        n = PI * 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 - 1; 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;
    

    if(minD == 0) break; } cout << num << "/" << denom << endl; } return 0; }

    string ltrim(const string &str) { string s(str);

    s.erase(
        s.begin(),
        find_if(s.begin(), s.end(), not1(ptr_fun<int, int>(isspace)))
    );
    
    return s;
    

    }

    string rtrim(const string &str) { string s(str);

    s.erase(
        find_if(s.rbegin(), s.rend(), not1(ptr_fun<int, int>(isspace))).base(),
        s.end()
    );
    
    return s;
    

    }

    vector split(const string &str) { vector tokens;

    string::size_type start = 0;
    string::size_type end = 0;
    
    while ((end = str.find(" ", start)) != string::npos) {
        tokens.push_back(str.substr(start, end - start));
    
        start = end + 1;
    }
    
    tokens.push_back(str.substr(start));
    
    return tokens;
    

    }