您的位置:首页 > 其它

HDU:1063 POJ:1001  Exponentiat…

2012-12-05 17:08 597 查看
这道题虽然题目要求清晰,可是要考虑的细节真实太多了,稍不注意就会出错

这是我的代码(注意:经常使用strrev函数的同学们在POJ上交的时候要自己编这个函数,因为这我CE了好几次!

):

先附带一下数据,不过的同学们可以测试一下:

00.000 20

0

5.1004 15

41120989454.314570363993506408035342551967503175087477761156936917581824

6.0092 20

3769929003093657.321962960746396532078795815950689066104211891790874779993410876

17646994418302976

90.909 20

1486406551798253233999195346707087657544.775949857477432123445196642299879937148

848818861186416630801

1.0001 20

1.002001901140484655078767753259867978477279725977752387615504484511400190002000

01

54.120 20

46468190221655199272477781205783832.2745385034134800709627347812689616306176

000.10 20

.00000000000000000001

12.010 20

3898164373852177448724.9596914878392975482722144801842193624001

1.1000 20

6.72749994932560009201

00.100 20

.00000000000000000001

.10000 25

.0000000000000000000000001

.98765 25

.7329539704323545929059725326336036315520737374975804183549501881226320403884675

7925736111183672158735201714336872100830078125

0000.1 25

.0000000000000000000000001

0.0001 1

.0001

0.0000 20

0

11.001 20

673974233702250167359.9626948260256710473510810408353137341213656411623629902200

01

110000 20

67274999493256000920100000000000000000000000000000000000000000000000000000000000

000000000000000000000

.00001 25

.0000000000000000000000000000000000000000000000000000000000000000000000000000000

0000000000000000000000000000000000000000000001

.00010 23

.0000000000000000000000000000000000000000000000000000000000000000000000000000000

0000000000001

1.0000 25

1

2.0000 25

33554432

6.0000 25

28430288029929701376

99.999 25

99975002999770012649468717709519310815545705768715.42652002479974457367312604296

4184298069822900531298735002299997000002499999

1 0

1

0 1

0

.00 1

0

95.123 12

548815620517731830194541.899025343415715973535967221869852721

0.4321 20

.0000000514855464107695612199451127676715483848176020072635120383542976301346240

1

5.1234 15

43992025569.928573701266488041146654993318703707511666295476720493953024

6.7592 9

29448126.764121021618164430206909037173276672

98.999 10

90429072743629540498.107596019456651774561044010001

1.0100 12

1.126825030131969720661201

.00001 1

.00001

.12345 1

.12345

0001.1 1

1.1

1.1000 1

1.1

10.000 1

10

000.10 1

.1

000000 1

0

000.00 1

0

.00000 0

1

000010 1

10

000.10 1

.1

0000.1 1

.1

00.111 1

.111

0.0001 1

.0001

0.0001 3

.000000000001

0.0010 1

.001

0.0010 3

.000000001

0.0100 1

.01

0.0100 3

.000001

0.1000 1

.1

0.1000 3

.001

1.0000 1

1

1.0000 3

1

1.0001 1

1.0001

1.0001 3

1.000300030001

1.0010 1

1.001

1.0010 3

1.003003001

1.0100 1

1.01

1.0100 3

1.030301

1.1000 1

1.1

1.1000 3

1.331

10.000 1

10

10.000 3

1000

10.001 1

10.001

10.001 3

1000.300030001

10.010 1

10.01

10.010 3

1003.003001

10.100 1

10.1

10.100 3

1030.301

99.000 1

99

99.000 3

970299

99.001 1

99.001

99.001 3

970328.403297001

99.010 1

99.01

99.010 3

970593.059701

99.100 1

99.1

99.100 3

973242.271

99.998 1

99.998

99.998 3

999940.001199992

代码:(有点儿复杂,不过在HDU和POJ上都还是过了



#include<stdio.h>

#include<string.h>

#define N 500

void quling(char str[])

{

    int n;

   
n=strlen(str)-1;

   
while(str
=='0')

       
n--;

   
str[n+1]='\0';

}

void Strrev(char str[])

{

    int
i,j=0;

    char
s[1009];

   
for(i=strlen(str)-1;i>=0;i--)

       
s[j++]=str[i];

   
s[j]='\0';

   
strcpy(str,s);

}

int range(char str[])

{

    int
i=0,num=0;

   
while(str[i]!='.'){

  i++;

  if(str[i]=='\0')

   break;

 }

   
if(str[i]!='\0')num--;

   
for(;str[i];i++)

    {

       
str[i]=str[i+1];

       
num++;

    }

    return
num;

}

void mul(char str_a
, char str_b
, char str_c
)

{   

    char
a
,b
;

    int
c[2*N];

    char
C[2*N];

    int
i,j,len_a,len_b;

   
memset(a,0,sizeof(a));

   
memset(b,0,sizeof(b));

   
memset(c,0,sizeof(c));

   
memset(C,0,sizeof(C));

   
strcpy(a,str_a);strcpy(b,str_b);

   
Strrev(a);Strrev(b);

   
len_a=strlen(a);len_b=strlen(b);

   
for(i=0;i<len_a;i++)

       
a[i]=a[i]-'0';

   
for(i=0;i<len_b;i++)

       
b[i]=b[i]-'0';

   
for(i=0;i<len_b;i++)

       
for(j=0;j<len_a;j++)

           
c[i+j]+=b[i]*a[j];

       
for(i=0;i<len_a+len_b;i++)

       
{

           
c[i+1]=c[i+1]+c[i]/10;

           
c[i]=c[i];

       
}

       
for(i=0;i<len_a+len_b;i++)

           
C[i]=c[i]+'0';

       
while(C[i]==0||C[i]=='0')i--;

       
C[i+1]=0;

       
Strrev(C);

       
strcpy(str_c,C);

}

int main()

{

   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: