UVA - 11809 Floating-Point Numbers


Sample Input

Sample Output

5.699141892149156e76

9.205357638345294e18

0e0

5 8

8 6

 

#include <bits/stdc++.h>
#define DET 1e-4
using namespace std;

double A[16][64];
long long int B[16][64];

void init()
{
    for(int i = 0; i <= 9; i++)
    {
        for(int j = 1; j <= 30; j++)
        {
            double E = 1 - pow(2, -(i+1));
            long long int M = pow(2, j) - 1;
            double X = log10(E) + M*log10(2);
            long long int b = floor(X);
            double a = pow(10.0, X-b);
            A[i][j] = a;
            B[i][j] = b;
        }
    }
}


int main()
{
    init();
    char in[32];
    while(cin >> in)
    {
        if(strcmp(in, "0e0")==0)
            break;
        double a;
        long long int b;
        *(strchr(in, 'e')) = ' ';
        sscanf(in, "%lf %lld", &a, &b);
        for(int i = 0; i <= 9; i++)
        {
            for(int j = 1; j <= 30; j++)
            {
                if(fabs(A[i][j]-a)<DET && B[i][j]==b)
                    printf("%d %d\n", i, j);
            }
        }
    }
    return 0;
}


posted @ 2014-11-26 08:50  Popco  阅读(211)  评论(0编辑  收藏  举报