| ||||||||||
| 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 | |||||||||
Re:求解1001题In Reply To:Re:求解1001题 Posted by:bigsword at 2010-11-02 22:50:03 > #include<stdio.h>
> #include <memory.h>
> #include <string.h>
> struct node
> {
> int num[150];
> int point;
> int cnt;
> }now,next;
> int min(int a,int b)
> {
> return a>b?b:a;
> }
> int maxn(int a,int b)
> {
> return a>b?a:b;
> }
> node multiply(node a,node b)
> {
> node c;
> c.cnt=0;
> c.point=a.point+b.point;
> memset(c.num,0,sizeof(c.num));
> int i,j,k,up;
> for(i=0;i<a.cnt;i++)
> for(j=0;j<b.cnt;j++)
> {
> if(i+j+1>c.cnt)
> c.cnt=i+j+1;
> c.num[i+j]+=a.num[i]*b.num[j];
> up=c.num[i+j]/10;
> c.num[i+j]%=10;
> k=1;
> while(up!=0)
> {
> c.num[i+j+k]+=up;
> if(i+j+k+1>c.cnt)
> c.cnt=i+j+k+1;
> up=c.num[i+j+k]/10;
> c.num[i+j+k]%=10;
> k++;
> }
> }
> return c;
> }
> int main()
> {
> char ch[100];
> int num;
> int i,j,k;
> int front,back;
> int len;
> while(scanf("%s%d",ch,&num)==2)
> {
> len=strlen(ch);
> memset(now.num,0,sizeof(now.num));
> now.cnt=0;
> for(i=0;i<len;i++)
> if(ch[len-i-1]=='.')
> now.point=i;
> else
> now.num[now.cnt++]=ch[len-1-i]-'0';
> next.cnt=1;
> next.point=0;
> memset(next.num,0,sizeof(next.num));
> next.num[0]=1;
> while(num)
> {
> if(num&1)
> next=multiply(next,now);
> num/=2;
> if(num!=0)
> now=multiply(now,now);
> }
> back=0;
> while(next.num[back]==0)
> back++;
> front=next.cnt;
> while(next.num[front]==0)
> front--;
> k=0;
> for(j=maxn(front,next.point);j>=min(back,next.point);j--)
> {
> if(j==next.point)
> {
> if(front<next.point)
> {
> printf(".");
> }
> else if(back>=next.point)
> {
> printf("%d",next.num[j]);
> }
> else
> {
> printf("%d",next.num[j]);
> printf(".");
> }
> }
> else
> printf("%d",next.num[j]);
> }
> printf("\n");
> }
> return 0;
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator