您的位置:首页 > 其它

UVa-11809 - Floating-Point Numbers

2015-02-26 23:07 423 查看
参考了http://blog.csdn.net/xyqcl/article/details/40011009

[code]#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    double aa[15][35]={};
    int bb[15][35]={};
    for(int m=0;m<=9;m++)
    {
        for(int e=1;e<=30;e++)
        {
            double tc=1-pow(2,-m-1);
            long long td=pow(2,e)-1;
            double t=log(tc)/log(10)+td*log(2)/log(10);
            bb[m][e]=t;
            aa[m][e]=pow(10,t-bb[m][e]);
        }
    }
    char s[30]={};
    while(cin>>s&&s[0]-'0')
    {
        double a;
        int b;
        s[17]=' ';
        sscanf(s,"%lf %d",&a,&b);
        for(int m=0;m<=9;m++)
            for(int e=1;e<=30;e++)
                if(fabs(aa[m][e]-a)<1e-6&&b==bb[m][e])
                    cout<<m<<" "<<e<<endl;
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: