POJ 1005: I Think I Need a Houseboat

来源:互联网 发布:淘宝联盟如何推广 编辑:程序博客网 时间:2024/06/03 18:35

解题要点: 类型转换的舍入问题.
double 转 int 的规则是向下舍入, 而非四舍五入.

代码如下:

#include <iostream>#include <cmath>using namespace std;const double PI = 3.14159265358979323846264338328;  // 其实不需要弄这么长int main() {    int n;    cin >> n;    double x, y;    for( int i = 1; i <= n; ++i ) {        cin >> x >> y;        cout << "Property " << i << ": This property will begin eroding in year "            << int( PI * ( x * x + y * y ) / 100.0 ) + 1 << "." << endl;    }    cout << "END OF OUTPUT." << endl;}
0 0
原创粉丝点击