| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
第一个样例都输出不正确的代码为什么可以ac?
在我的编译器中,这个代码输出第一个样例是99.难道pow的精度跟编译器有关?
#include "stdio.h"
#include "memory.h"
#include "string.h"
#include "math.h"
char w[12],x[12];
int countddz()
{
int len,m,i,j,pos[12],h,t,r,result,numx,numw,d;
char w1[12];
len = strlen(w);
m = 0;
for (i = 0; i <= len - 1; i ++)
if (w[i] == '?')
{
m ++;
pos[m] = i;
}
h = 0;
t = (int)pow(10.0,m);
result = -1;
if (m == 0)
result = 0;
if (result == -1)
{
strcpy(w1,w);
for (i = 0; i <= len - 1; i ++)
if (w[i] == '?')
w1[i] = 9 + '0';
if (strcmp(w1,x) < 0) result = 0;
for (i = 0; i <= len - 1; i ++)
if (w[i] == '?')
w1[i] = 0 + '0';
if (strcmp(w1,x) > 0)
result = t;
}
if (result == -1)
{
numx = 0;
for (i = len - 1; i >= 0; i --)
numx += (x[i] - '0') * (int)pow(10.0,len - 1 - i);
strcpy(w1,w);
while (t - h > 1)
{
r = (t + h) / 2;
for (i = m; i >= 1; i --)
{
d = r % 10;
r = r / 10;
w1[pos[i]] = d + '0';
}
if (strcmp(w1,x) > 0)
t = (t + h) / 2;
else
h = (t + h) / 2;
}
r = t;
for (i = m; i >= 1; i --)
{
d = r % 10;
r = r / 10;
w1[pos[i]] = d + '0';
}
if (strcmp(w1,x) <= 0)
result = (int)pow(10.0,m) - 1 - t;
r = h;
for (i = m; i >= 1; i --)
{
d = r % 10;
r = r / 10;
w1[pos[i]] = d + '0';
}
if (strcmp(w1,x) <= 0)
result = (int)pow(10.0,m) - 1 - h;
}
printf("%d\n",result);
return 0;
}
int main()
{
while (scanf("%s",w) != EOF && strcmp(w,"#") != 0)
{
scanf("%s",x);
countddz();
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator