Skip to content

Instantly share code, notes, and snippets.

@Acarus
Created May 1, 2017 16:56
Show Gist options
  • Save Acarus/a9022a3fac99891399ebb58879ebce22 to your computer and use it in GitHub Desktop.
Save Acarus/a9022a3fac99891399ebb58879ebce22 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
string solve(int num, string rem, int n) {
if (n == 0) {
if (rem[0] >= '5') return to_string(num + 1);
else return to_string(num);
} else {
if (n == rem.size()) return to_string(num) + "." + rem;
if (rem[n] >= '5') ++rem[n - 1];
return to_string(num) + "." + rem.substr(0, n);
}
}
int main() {
int n;
cin >> n;
cout << solve(2, "7182818284590452353602875", n) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment