/*
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