Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594

POJ 1001 求高精度幂---高精度

Posted on 2009-09-03 02:00 Uriel 阅读(3053) 评论(1)  编辑 收藏 引用 所属分类: POJ模拟
很久之前做的了。。当时还什么都不会。。死搞这一题14小时之后一次AC。。瘫倒。。但是很高兴。。
用这题激励下自己。。坚决不放弃!!
(代码很恶心啊。。改来改去面目全非。。大家忽略。。)
/*Problem: 1001  User: Uriel 
   Memory: 204K  Time: 0MS 
   Language: C  Result: Accepted
*/
 

#include
<stdio.h>
#include
<string.h>

int main()
{   
    
int n,i,j,flag,g,k,b[6],pos,spos,sum[200],key,temp[200],temp1[200];
    
char a[7];
    memset(a,
0x00,sizeof(a));
    
while(scanf("%s %d",a,&n)!=EOF)
    
{
        
for(i=0;i<200;i++){sum[i]=0;temp1[i]=0;}
        j
=0;
        flag
=5;
        
for(i=5;i>=0;i--)                
        
{
            
if(a[i]=='.')flag=i;
            
else 
            
{
                b[j]
=a[i]-'0';
                temp1[j]
=b[j];
                j
++;
            }

        }
            
        pos
=0;
        spos
=5;
        
for(k=1;k<n;k++)
        
{
            
for(i=0;i<5;i++)
            
{
                
for(j=0;j<spos;j++)
                
{
                    sum[i
+j]+=(temp1[j]*b[i]);
                
//    temp[i+j]=sum[i+j];
                
//    sum[i+j]-=(temp1[j]*b[i]);
                }

            }

            key
=sum[0]/10;
            sum[
0]%=10;
            
for(i=1;i<spos+4;i++)
            
{
                sum[i]
+=key;
                key
=sum[i]/10;//printf("key=%d ",key);
                sum[i]%=10;//printf("sum=%d ",sum[i]);
            }

            sum[i]
=key%10;//printf("sum=%d ",sum[i]);
            if(sum[i]!=0)pos++;
            i
++;
            
while((key/10)>0)
            
{
                key
/=10;
                sum[i]
=key%10;
                pos
++;//printf("add pos");
                i++;
            }

            spos
=spos+4+pos;//printf("spos=%d ",spos);
            for(i=0;i<spos;i++){temp1[i]=sum[i];sum[i]=0;}//printf("temp1=%d  ",temp1[i]);}//printf("sum=%d ",sum[8]);
        }

        
        
for(j=199;j>=(5-flag)*n;j--)
        
{
            
if(temp1[j]==0)continue;
            
else
                
break;
        }

        
for(g=0;g<=(5-flag)*n-1;g++)
        
{
            
if(temp1[g]==0)continue;
            
else
                
break;
        }
                    
        
for(i=j;i>=(5-flag)*n;i--
        
{
            printf(
"%d",temp1[i]);
        }

        
if(g<(5-flag)*n)printf(".");
        
for(i=(5-flag)*n-1;i>=g;i--)printf("%d",temp1[i]);
        printf(
"\n");                
    }

    
return 0;
}

Feedback

# re: POJ 1001 求高精度幂---高精度  回复  更多评论   

2011-04-14 22:51 by code
加油啊

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理