题解 | #求解立方根# 穷举法
求解立方根
https://www.nowcoder.com/practice/caf35ae421194a1090c22fe223357dca
#include <iostream> #include <cmath> using namespace std; int main(){ double num; while( cin >> num ){ double res=0; if( num > 0 ){ for(double i=0.00001; i<15; i=i+0.00001){ if( abs(num - i*i*i) <= 0.0001 ){ res = i; // cout << i << " " << num-i*i*i << endl; } } printf("%.1f\n", res); } if( num < 0 ){ for(double i=-0.00001; i>-15; i=i-0.00001){ if( abs(num - i*i*i) <= 0.0001 ){ res = i; // cout << i << " " << num-i*i*i << endl; } } printf("%.1f\n", res); } if( num == 0 ) printf("%.1f\n", res); } return 0; }