poj1001
#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的更多相关文章
- 高精度POJ1001
今天看到这道题了 poj1001 题目地址是http://bailian.openjudge.cn/practice/1001/ 英文看得懂,可是算法不明白,所以转别人的文章,留着给学生看看:乔高建( ...
- POJ-1001 Exponentiation 高精度算法
题目链接:https://cn.vjudge.net/problem/POJ-1001 以前写过一个高精度乘法,但是没有小数点,实现起来也没什么难得, 现在把代码都般过来,等会把旧电脑弄一弄,暂时就不 ...
- poj1001 Exponentiation 大数的幂
Description Problems involving the computation of exact values of very large magnitude and precision ...
- 【poj1001】 Exponentiation
http://poj.org/problem?id=1001 (题目链接) 题意 求实数R的n次方,要求高精度. Solution SB题Wa了一下午,直接蒯题解. 高精度,小数点以及去前导后导零很麻 ...
- 北大poj-1001
Description Problems involving the computation of exact values of very large magnitude and precision ...
- poj1001 Exponentiation
Description Problems involving the computation of exact values of very large magnitude and precision ...
- C# 高精度求幂 poj1001
高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...
- poj1001(高精度)
Exponentiation Time Limit: 500MS Memory ...
- poj1001求幂
这道题目是实质上就是高精度的乘法,虽然是带小数点的数多少次幂,但是开始我们需要将它变为整数进行求幂,然后再加上小数点,然后要考虑前导0,有效数位问题,做的时候要十分的小心 #include<io ...
随机推荐
- Selenium+PyCharm环境搭建
一.首先安装python并配置好环境变量 二.安装selenium 安装文件夹在安装的python文件夹下,例:D:\Program\python\Lib\site-packages\selenium ...
- Codeforces831C Jury Marks
C. Jury Marks time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 2018/9/6 spring框架的整理
spring知识的巩固整理AOP和ioc概念,以及了解到了为何要使用spring框架的目的,作用:变换资源获取的方向.更像是按需所求.配置bean的方式:利用XML的方式,基于注解的方式两种.1通过全 ...
- listcard记录
.listcard-bg{ .listcard-head{ background: #F34A55; width: 100%; height: 50px; margin-bottom: -50px; ...
- [转] Snapshotting with libvirt for qcow2 images
http://kashyapc.com/2011/10/04/snapshotting-with-libvirt-for-qcow2-images/ Libvirt 0.9.6 was recentl ...
- html input file accept 上传文件类型限制格式 MIME 类型列表
例: <input type="file" accept="application/vnd.openxmlformats-officedocument.spread ...
- CSS3圆角详解第一辑
有很多人都知道圆角怎么写,加一个border-radius就可以,但是对于用圆角的一些细节却并不是很清楚,那么我们今天就来聊一聊这个圆角.CSS3是样式表(style sheet)语言的最新版本,它的 ...
- C/C++ 多线程机制
一.C/C++多线程操作说明 C/C++多线程基本操作如下: 1. 线程的建立结束 2. 线程的互斥和同步 3. 使用信号量控制线程 4. 线程的基本属性配置 在C/C++代码编写时,使用多线程机制, ...
- 吴恩达机器学习笔记22-正则化逻辑回归模型(Regularized Logistic Regression)
针对逻辑回归问题,我们在之前的课程已经学习过两种优化算法:我们首先学习了使用梯度下降法来优化代价函数
- Docker学习笔记-CentOS7镜像
前言: 环境:centos7.5 64 位 正文: 第一步:下载centos7镜像 docker pull centos 第二步:建立centos7的容器 sudo docker run --priv ...