We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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";
Minimal Distance to Pi
You are viewing a single comment's thread. Return to all 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);
{
long num, denom; double dist1, dist2, minD = PI; long n; //cout << PI << "\t" << to_string(PI) << endl;
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;
if(minD == 0) break; } cout << num << "/" << denom << endl; } return 0; }
string ltrim(const string &str) { string s(str);
}
string rtrim(const string &str) { string s(str);
}
vector split(const string &str) { vector tokens;
}