POJ_1001 Exponentiation
来源:互联网 发布:java date setmonth 编辑:程序博客网 时间:2024/06/06 04:11
http://poj.org/problem?id=1001
/*
Description: 基本思想很简单:把double型当做字符串进行读入,然后提取出double的各个数到int型
数组中,模拟手算进行大整数乘法。
注意:要事先计算出小数点的位置,输出的时候加以控制即可!
*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
Description: 基本思想很简单:把double型当做字符串进行读入,然后提取出double的各个数到int型
数组中,模拟手算进行大整数乘法。
注意:要事先计算出小数点的位置,输出的时候加以控制即可!
*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef string::size_type size_type;
int ans[10024 + 10];
void Print(int *d, int size)
{
for(int i = size - 1; i >= 0; --i)
cout<<ans[i]<<" ";
cout<<endl;
}
{
for(int i = size - 1; i >= 0; --i)
cout<<ans[i]<<" ";
cout<<endl;
}
int Transfer(int *d, int size)
{
int res = 0;
memset(ans, 0, sizeof(ans));
for(int i = 0; i < size; ++i){
res = res*10 + d[i];
ans[size-1-i] = d[i];
}
return res;
}
{
int res = 0;
memset(ans, 0, sizeof(ans));
for(int i = 0; i < size; ++i){
res = res*10 + d[i];
ans[size-1-i] = d[i];
}
return res;
}
void Multiply(int& size, int r)
{
int sh = 0;
for(int i = 0; i < size; ++i){
int temp = ans[i]*r + sh;
ans[i] = temp%10;
sh = temp/10;
}
int k = size;
if(sh > 0){
while(sh){
ans[k++] = sh%10;
sh /= 10;
}
size = k;
}
}
{
int sh = 0;
for(int i = 0; i < size; ++i){
int temp = ans[i]*r + sh;
ans[i] = temp%10;
sh = temp/10;
}
int k = size;
if(sh > 0){
while(sh){
ans[k++] = sh%10;
sh /= 10;
}
size = k;
}
}
int main()
{
string dl;
int n;
while(cin>>dl>>n){
size_type pos = dl.find('.', 0);
int d[6] ;
bool sign = 0;
int index = 0;
if(pos == string::npos)
pos = dl.size();
/* begin-->提取出double*/
for(size_type i = 0; i < pos; ++i)
if(sign){
d[index++] = dl[i] - '0';
}
else if(dl[i] != '0'){
d[index++] = dl[i] - '0';
sign = 1;
}
size_type up = dl.size() - 1;
while(dl[up] == '0')
--up;
for(size_type i = pos+1; i <= up; ++i)
d[index++] = dl[i] - '0';
/* end */
int r = Transfer(d, index);
int size = index;
for(int i = 1; i < n; ++i)
Multiply(size, r);
int point_pos = (up - pos)*n - 1;
if(point_pos > size-1){
cout<<".";
for(int i = point_pos; i >= size; --i)
cout<<0;
}
for(int i = size - 1; i >= 0; --i){
if(i == point_pos)
cout<<".";
cout<<ans[i];
}
cout<<endl;
}
//system("pause");
return 0;
}
{
string dl;
int n;
while(cin>>dl>>n){
size_type pos = dl.find('.', 0);
int d[6] ;
bool sign = 0;
int index = 0;
if(pos == string::npos)
pos = dl.size();
/* begin-->提取出double*/
for(size_type i = 0; i < pos; ++i)
if(sign){
d[index++] = dl[i] - '0';
}
else if(dl[i] != '0'){
d[index++] = dl[i] - '0';
sign = 1;
}
size_type up = dl.size() - 1;
while(dl[up] == '0')
--up;
for(size_type i = pos+1; i <= up; ++i)
d[index++] = dl[i] - '0';
/* end */
int r = Transfer(d, index);
int size = index;
for(int i = 1; i < n; ++i)
Multiply(size, r);
int point_pos = (up - pos)*n - 1;
if(point_pos > size-1){
cout<<".";
for(int i = point_pos; i >= size; --i)
cout<<0;
}
for(int i = size - 1; i >= 0; --i){
if(i == point_pos)
cout<<".";
cout<<ans[i];
}
cout<<endl;
}
//system("pause");
return 0;
}
本文出自 “东方快翔” 博客,请务必保留此出处http://hustluy.blog.51cto.com/1792080/832191
- POJ_1001 Exponentiation
- poj_1001 Exponentiation 高精度乘法
- POJ_1001(Exponentiation) 求高精度幂 攻略中...
- POJ_1001
- POJ_1001
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- Exponentiation
- poj_1001 高精度浮点
- 大数阶乘
- c语言中字符串处理函数
- scanf与gets函数读取字符串的区别
- 华中科技大学2010年复试上机题a+b
- 取石子游戏POJ1067
- POJ_1001 Exponentiation
- POJ_2593最大两不想交子段和问题
- C语言复杂的类型声明
- 差分进化g05测试代码
- Linux命令之tar包
- 自动类型转化的鲜为人知的陷阱
- windows下tracert程序实现
- 统计一个数组中相同元素个数
- 百度之星12月23号题目之du熊做实验