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 ...
随机推荐
- There is no getter for xxx 或者 will not be managed by Spring 解决
今天使用mysql 的sql查询语句的时候(我是用的是ssm框架) 下面是我的查询语句,条件是根据business_id 和card_status 两个参数获取值 select * from tb_ ...
- 分别求二叉树前、中、后序的第k个节点
一.求二叉树的前序遍历中的第k个节点 //求先序遍历中的第k个节点的值 ; elemType preNode(BTNode *root,int k){ if(root==NULL) return ' ...
- spring深入学习(三)-----spring容器内幕
之前都是说了怎么配置bean以及用法之类的,这篇博文来介绍下spring容器内幕. 内部容器工作机制 Spring中AbstractApplicationContext抽象类的refresh()方法是 ...
- 1013. Battle Over Cities 用dfs计算联通分量
使用一个标记数组,标记 节点是否已访问 int 连通度=0 dfs(node i) {标记当前节点为以访问 for(每一个节点) {if(当前几点未访问 并且 从i到当前节点有直接路径) dfs(当前 ...
- 负载均衡器之 Haproxy
1. 编译安装haproxy 官网: http://www.haproxy.org 1.1 下载haproxy # wget http://www.haproxy.org/download/1.6/s ...
- C++ STL next_permutation(快速排列组合)
排列组合必备!! https://blog.csdn.net/bengshakalakaka/article/details/78515480
- Exp5 MSF基础运用 20154320 李超
实验后回答问题 用自己的话解释什么是exploit,payload,encode. exploit:起运输的作用,将数据传输到对方主机. payload:其实就是指装载的“具体内容”.就相当于shel ...
- Leetcode35 Search Insert Position 解题思路(python)
本人编程小白,如果有写的不对.或者能更完善的地方请个位批评指正! 这个是leetcode的第35题,这道题的tag是数组,python里面叫list,需要用到二分搜索法 35. Search Inse ...
- 【webpack】-- 入门与解析
每次学新东西总感觉自己是不是变笨了,看了几个博客,试着试着就跑不下去,无奈只有去看官方文档. webpack是基于node的.先安装最新的node. 1.初始化 安装node后,新建一个目录,比如ht ...
- 「HNOI2016」数据结构大毒瘤
真是 \(6\) 道数据结构毒瘤... 开始口胡各种做法... 「HNOI2016」网络 整体二分+树状数组. 开始想了一个大常数 \(O(n\log^2 n)\) 做法,然后就被卡掉了... 发现直 ...