ZOJ 1242 Carbon Dating

来源:互联网 发布:淘宝类目是什么意思 编辑:程序博客网 时间:2024/04/28 19:02

#include <math.h>
#include <stdio.h>
int main()
{
    double w,d,s,t;
    int k=1;
    while (scanf("%lf%lf",&w,&d),w||d)
    {
        s=t=log((w*810)/d)/log(2.0)*5730;
        if (s<10000)
        {
            t=floor(t/100)*100;
            s=s-t>=50?t+100:t;
        }
        else
        {
            t=floor(t/1000)*1000;
            s=s-t>=500?t+1000:t;
        }
        printf("Sample #%d/nThe approximate age is %0.0lf years./n/n",k++,s);
    }
    return 0;
}

 

注:这个题,注意四舍五入,发现整数比较要比+0.5这种方法精确,注意

原创粉丝点击