Exponentiation
Description
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.
This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999) and n is an integer such that $0 < n \le 25$.
Input
The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.
Output
The output will consist of one line for each line of input giving the exact value of Rn. Leading zeros and insignificant trailing zeros should be suppressed in the output.
Sample Input
95.123 12
0.4321 20
5.1234 15
6.7592 9
98.999 10
1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
HINT
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char str[1000],a[1000],a1[1000];
int c;
int n,i,j,k,t,x,num,t1,t2,y,y1,y2;
while(cin>>str>>n)
{ x=0;num=0;
t=strlen(str);
for(i=0;i<t;i++)
{
if(str[i]=='.')
{
num=t-1-i;
i++;
}
a[x]=str[i];
a1[x++]=str[i];
}
a[x]='\0';
a1[x]='\0';
num*=n;
int x1=x;
for(i=0;i<n-1;i++)
{
int sum[1000]={0};
t1=999;t2=999;
for(j=x-1;j>=0;j--)
{
for(k=x1-1;k>=0;k--)
sum[t1--]+=((a[j]-'0')*(a1[k]-'0'));
t2--;
t1=t2;
}
c=0;
for(y=999;y>=0;y--)
{
sum[y]+=c;
c=0;
if(sum[y]>9)
{
c=sum[y]/10;
sum[y]=sum[y]%10;
}
}
for(y1=0;y1<1000;y1++)
{
if(sum[y1]!=0)
break;
}
x1=0;
for(y2=y1;y2<1000;y2++)
a1[x1++]=sum[y2]+'0';
a1[x1]='\0';
}
if(num==0)
cout<<a1<<endl;
else
{
t=strlen(a1);
if(a1[t-1]=='0')//若(2.0, 2)则输出4而不是4.00,多余的零去掉
{
for(i=t-1;i>=0;i--)
{
if(a1[i]!='0')
break;
num--;//小数点的位数
}
t=i+1;
}
for(i=0;i<t-num;i++)
cout<<a1[i];//输出小数点之前的
cout<<".";
while(num>t-i)//若整数部分为0,小数部分不够填补小数点后的位数0
{
cout<<"0";
num--;
}
for(j=i;j<t;j++)
cout<<a1[j];//输出小数点后的
cout<<endl;
}
}
return 0;
}
Exponentiation的更多相关文章
- 【PKU1001】Exponentiation(高精度乘法)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 145642 Accepted: 35529 ...
- uva748 - Exponentiation
import java.io.*; import java.text.*; import java.util.*; import java.math.*; public class Exponenti ...
- [POJ] #1001# Exponentiation : 大数乘法
一. 题目 Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 156373 Accepted: ...
- Poj 1001 / OpenJudge 2951 Exponentiation
1.链接地址: http://poj.org/problem?id=1001 http://bailian.openjudge.cn/practice/2951 2.题目: Exponentiatio ...
- POJ 1001 Exponentiation 无限大数的指数乘法 题解
POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...
- HDU Exponentiation 1063 Java大数题解
Exponentiation Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- Problem F: Exponentiation
Problem F: ExponentiationTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 4 Solved: 2[Submit][Status][W ...
- Exponentiation(java 大实数)
http://acm.hdu.edu.cn/showproblem.php?pid=1063 Exponentiation Time Limit: 2000/500 MS (Java/Others) ...
- ( 大数 startsWith substring) Exponentiation hdu1063
Exponentiation Time Limit: 2000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1001 Exponentiation(大数运算)
POJ 1001 Exponentiation 时限:500 ms 内存限制:10000 K 提交材料共计: 179923 接受: 43369 描述:求得数R( 0.0 < R < ...
随机推荐
- flash跨域策略文件crossdomain.xml
flash在跨域时唯一的限制策略就是crossdomain.xml文件,该文件限制了flash是否可以跨域读写数据以及允许从什么地方跨域读写数据. 位于www.a.com域中的SWF文件要访问www. ...
- Boost::Thread使用示例 - CG-Animation - 博客频道 - CSDN.NET
Boost::Thread使用示例 - CG-Animation - 博客频道 - CSDN.NET Boost::Thread使用示例 分类: C/C++ 2011-07-06 14:48 5926 ...
- 顺序栈之C++实现
顺序栈就是用顺序表(数组)实现的栈.其组织形式如下图所示: 下面介绍下我用C++实现的顺序栈,在VC6下调试通过.不足之处还请指正. 1.文件组织 2.ss.h栈类的声明及宏的定义 #ifndef _ ...
- 起启航-华夏互联与杰华网络合体结盟打造本土IT利舰
北京时间2013年9月9日消息: 领先的软件研发企业上海逐一软件科技有限公司与专业互联网推广运营机构南昌杰华网络开发有限公司达成协议,双方将建立紧密合作关系与集团运营体制,并在未来的10个月内进行相应 ...
- UVA507-- Jill Rides Again
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- c# 搭建服务端 常用的Helper(5)
常用的Helper 1.byteHelper :对象与byte[]之间的转换 2.ConvertJson:操作json对象 3.EncodingHelper:对象编码 4.ModelConvertHe ...
- saiku中默认级别all的国际化
在制作saiku的schema文件的时候,当你选择层次的属性hasAll为true的时候,系统默认会为你的层次添加一个“(all)”级别,你无法给它增加一个caption属性来国际化它,因为他不是你创 ...
- Joseph(约瑟夫环)
Joseph Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- linux下Oracle11g RAC搭建(六)
linux下Oracle11g RAC搭建(六) 五.校验安装前的环境 root身份下完毕解压grid.database安装包 [grid@node1 soft]$ su - Password: [r ...
- CSS定位深入理解 完全掌握CSS定位 相对定位和绝对定位
其实前面的标准流和浮动流都很理解,就是定位不太好理解,特别是相对定位和绝对定位,很多刚开始学的同学不好区分.因此这里,小强老师和大家一起分享CSS定位的学习. 通过我们前面的学习,我们网页布局方法: ...