#include <iostream>
#include<iomanip>
#include<cstring>
using namespace std;
int s;
void chen(char a[],char b[])//a=a*b
{ int i,j,k,l,sum,c[]={};
l=strlen(a)+strlen(b);
for(i=strlen(b)-;i>=;i--)
for(j=strlen(a)-,k=i+j+;j>=;j--,k--)
{ sum=(b[i]-'')*(a[j]-'')+c[k];
c[k]=sum%;c[k-]+=sum/;
}
for(i=c[]?:,j=;i<l;i++)
a[j++]=(c[i]+''); a[j]=;
}
void quw0(char a[]) //去除尾部多余的零
{ int i=strlen(a)-;
while(a[i]=='') {a[i]=;i--;}
} void jilu(char a[])
{ int i,t;
for(i=;i<strlen(a);i++) //判断有没有小数点
if(a[i]=='.') break;
if(i!=strlen(a)) //有小数点
{
for(i=strlen(a)-,s=;i>=;i--)// s记录小数位数
if(a[i]!='.') s++;
else break;
if(a[i=]=='') // 0.0123变成123
{ for(i=;i<strlen(a);i++)
if(a[i]!='') {strcpy(a,&a[i]);break;}
}
else //将1.4321 变成14321
{ for(t=,i=;i<strlen(a)-;i++)
{ if(a[i]=='.') t=;
if(t) a[i]=a[i+];
}
a[i]=;
}
} } void show(char a[])
{ int i;
if(s>=strlen(a)) cout<<'.'<<setfill('')<<setw(s)<<a<<endl;// 前面补零
else //不用补零,直接加入小数点输出
{for(i=;i<strlen(a);i++)
if(strlen(a)-s==i) {cout<<'.'<<&a[i]; break;}
else cout<<a[i];
cout<<endl;
} } int main()
{
int n; char b[],a[];
while(cin>>b>>n)
{ if(n==) {cout<<<<endl;continue;}
s=;
quw0(b);
jilu(b);
strcpy(a,b);
for(int i=;i<=n;i++)
chen(a,b);
s*=n; //结果的小数位数
show(a);
}
return ;
}

poj1001的更多相关文章

  1. 高精度POJ1001

    今天看到这道题了 poj1001 题目地址是http://bailian.openjudge.cn/practice/1001/ 英文看得懂,可是算法不明白,所以转别人的文章,留着给学生看看:乔高建( ...

  2. POJ-1001 Exponentiation 高精度算法

    题目链接:https://cn.vjudge.net/problem/POJ-1001 以前写过一个高精度乘法,但是没有小数点,实现起来也没什么难得, 现在把代码都般过来,等会把旧电脑弄一弄,暂时就不 ...

  3. poj1001 Exponentiation 大数的幂

    Description Problems involving the computation of exact values of very large magnitude and precision ...

  4. 【poj1001】 Exponentiation

    http://poj.org/problem?id=1001 (题目链接) 题意 求实数R的n次方,要求高精度. Solution SB题Wa了一下午,直接蒯题解. 高精度,小数点以及去前导后导零很麻 ...

  5. 北大poj-1001

    Description Problems involving the computation of exact values of very large magnitude and precision ...

  6. poj1001 Exponentiation

    Description Problems involving the computation of exact values of very large magnitude and precision ...

  7. C# 高精度求幂 poj1001

    高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...

  8. poj1001(高精度)

                                                               Exponentiation Time Limit: 500MS   Memory ...

  9. poj1001求幂

    这道题目是实质上就是高精度的乘法,虽然是带小数点的数多少次幂,但是开始我们需要将它变为整数进行求幂,然后再加上小数点,然后要考虑前导0,有效数位问题,做的时候要十分的小心 #include<io ...

随机推荐

  1. java 排序算法

    1.冒泡排序 public static void main(String[] args) { int[] arr={6,3,8,2,9,1}; System.out.println("排序 ...

  2. linu输出重定向

    1.tee命令 ls | tee filename #若出现Permission Denied使用下面 ls | sudo tee filename #清空filename后重写 ls | sudo ...

  3. tensorflow学习之(七)使用tensorboard 展示神经网络的graph/histogram/scalar

    # 创建神经网络, 使用tensorboard 展示graph/histogram/scalar import tensorflow as tf import numpy as np import m ...

  4. 【翻译】Flume 1.8.0 User Guide(用户指南) Channel

    翻译自官网flume1.8用户指南,原文地址:Flume 1.8.0 User Guide 篇幅限制,分为以下5篇: [翻译]Flume 1.8.0 User Guide(用户指南) [翻译]Flum ...

  5. kvm+webvirtmgr在centos7上的部署

    #!/bin/bash #+++++++++++++++++++++++++++++++++++++++++++++++++++++++安装配置kvm并创建虚拟机+++++++++++++++++++ ...

  6. easyui属性赋值

    了解easyui tree组件的童鞋估计都知道tree的node有他自己单独的属性(id,text,iconCls,checked,state,attribute,target).而原先这个几个属性想 ...

  7. mac下crontab定时任务使用

    这篇文章的作用 BREAK TIME 本地pc配置定时任务,开机后每隔一小时执行一次,open这个页面,休息半分钟 cron创建备忘 首先创建定时任务 crontab -e 0 */ * * * op ...

  8. ruby module extend self vs module_funciton

    最近学习ruby过程中,extend self 跟 module_function 傻傻分不清楚,查资料后明白之间的差别,虽记录之,原文地址 github module A extend self d ...

  9. 用clock()函数计时的坑

    程序中经常用time()函数来返回当前系统时间的秒数,来计时或计算时间差.如果需要用到更高精度的时间,就会自然想到用clock()函数.想当然的认为它返回从程序开始tick数,用clock()/CLO ...

  10. formated time string for file naming

    #include <stdio.h> #include <time.h> int main() { time_t rawtime; struct tm *timeinfo; ] ...