题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1063
#include <stdio.h> #include <string.h> #include <stdlib.h> int memory[130]={1,0}; int len; void multiplication(int n) { int carry=0,i; for(i=0;i<len;i++) { memory[i]=memory[i]*n; memory[i]+=carry; carry=memory[i]/10; memory[i]=memory[i]%10; } while(carry!=0) { memory[len]=carry%10; carry=carry/10; len++; } } int main() { char str[7],*p,*q,num[7]; int n,m; int i; int point=0,flag; while(scanf("%6s%2d",&str,&n)==2) { len=strlen(str); point=0; flag=1; memset(memory,0,sizeof(memory)); memory[0]=1; memset(num,0,sizeof(num)); for(i=0;i<len;i++) { if(str[i]=='.') { flag=0; break; } } i=len-1; while(str[i]=='0'&&flag==0) //处理小数后面的0 { i--; len--; } if(len==0) { m=0; len=1; } else { p=str; i=0; while(str[i]=='0') { i++; p++; } len=len-i; q=p; i=0; while(*p!='.'&&i<len) { p++; i++; } point=len-i-1; for(i=0;i<len;i++,q++) { if(*q=='.') { len--;i--; } else num[i]=*q; } if(len==0) { m=0; len=1; } else m=atoi(num); } if(m==0&&n==0) { printf("1 "); continue; } else if(m==0) { printf("0 "); continue; } for(i=0;i<n;i++) { multiplication(m); } point*=n; if(point>=len) { printf("."); for(i=0;i<point-len;i++) printf("0"); for(i=len-1;i>=0;i--) printf("%d",memory[i]); } else { for(i=len-1;i>=0;i--) { if(i==point-1) printf("."); printf("%d",memory[i]); } } printf(" "); } }