感觉很简单,但在格式上好麻烦,导致调了很久才AC。还有就是乘法过程搞混了。。有点2,,不过最后还是AC了
#include <stdio.h>
#include <string.h>
#define MAX 500
int exp;
//最终结果
int result[MAX];
//输入字符
char s[6];
//小数点位置
int point=-1;
void cal(int exp)
{
int i;
//不考虑小数点时的数值
int temp_value=0;
//进位
int jinwei=0;
int j;
int n;
int c=0;
for(i=0;i<6;i++)
{
if(s[i]=='.')
{
point=i; break;
}
}
for(i=0;i<6 ;i++)
{
if(i!=point){
temp_value=temp_value*10+s[i]-'0';
}
}
c=0;
result[MAX-1]=1;
for(i=0;i<exp;i++)
{
jinwei=0;
for(j=MAX-1;j>=0;j--)
{
result[j]*=temp_value;
}
jinwei=0;
for(j=MAX-1;j>=0;j--)
{
result[j]+=jinwei;
jinwei=result[j]/10;
result[j]%=10;
}
}
}
void print()
{
int i,j,begin,end;
for(i=0;i<MAX;i++){
if(result[i]!=0) {
begin=i;
break;
}
}
for(i=MAX-1;i>=0;i--){
if(result[i]!=0) {
end=i;
break;
}
}
if(point!=-1){
j=MAX-(5-point)*exp;
for(i=begin;i<j;i++){
printf("%d",result[i]);
}
if(end>=j){
printf(".");
}
for(i=j;i<=end;i++){
printf("%d",result[i]);
}
}
else{
for(j=begin;j<MAX;j++){
printf("%d",result[j]);
}
}
printf("\n");
}
void main()
{
while(scanf("%s%d",s,&exp)==2)
{
memset(result,0,sizeof(int)*MAX);
cal(exp);
print();
}
}