//
第三章的最后一道题, 当时没敢看, 也是醉了。 后来ACM群里讨论了, 有点印象, 现在仔细看也不是很难。
//
1、那个样例的第二个A(算法入门)是0.5*1+0.5/2+0.5/2/2 +0.5/...2(除八个二), 这是计算机的储存方式。 仅仅知道这里而已。
2.INF要取到10的-4-6都行, 但是10的-10不行。
3.两边对数, 打表, 直观。
<pre name="code" class="cpp">#include <iostream>
#include <cstdio>
#include <string.h>
#include<math.h>
#include<algorithm>
const int maxn = 30 + 5;
const double INF = 1e-6;
using namespace std;
const int E[maxn] = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383,
32767, 65535, 131071, 262143, 524287, 1048575, 2097151, 4194303, 8388607, 16777215, 33554431,
67108863, 134217727, 268435455, 536870911, 1073741823};
const double M[maxn] = {0.5, 0.75, 0.875, 0.9375,0.96875, 0.984375, 0.9921875, 0.99609375, 0.998046875,
0.9990234375, 0.99951171875};
char str[maxn];
int main()
{
while(scanf("%s", str) && strcmp(str, "0e0") != 0)
{
*(strchr(str, 'e')) = ' ';
int EE, B;
double MM, A, BB;
sscanf(str, "%lf %d", &A, &B);
BB = log10(A) + B;
for(int i = 0; i <= 9; i++)
{
for(int j = 1; j <= 30; j++)
{
if(fabs( (log10(M[i]) + E[j] * log10(2)) - BB) < INF)
{
printf("%d %d\n", i, j);
break;
}
}
}
}
return 0;
}