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 <= 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 R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don’t print the decimal point if the result is an integer.

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

If you don’t know how to determine wheather encounted the end of input:

s is a string and n is an integer

C++

while(cin>>s>>n)

{

}

c

while(scanf(“%s%d”,s,&n)==2) //to see if the scanf read in as many items as you want

/while(scanf(%s%d”,s,&n)!=EOF) //this also work /

{

}

#include <iostream>
#include <string.h>
using namespace std;
int a[200];
int main()
{
int n,i,j;
string s;
while(cin>>s>>n)
{
memset(a,0,sizeof(a));
if(n == 0)
{
cout<<1<<endl;
continue;
}
bool flag = 1;
int pos = 0,base = 0,count = 0,bit = 1;
for(i = s.length()-1,j = 0; i >= 0; i--)
{
if(s[i] == '0'&&flag) count++;
else
{
flag = 0;
if(s[i] == '.')
pos = s.length()-count-i-1;
else
{
a[j++] = s[i] - '0';
base += (s[i] - '0')*bit;
bit *= 10;
} }
}
for(i = 0; i < n-1; i++)
{
int m = 0;
for(j = 0; j < 300; j++)
{
m += base * a[j];
a[j] = m % 10;
m /= 10;
}
}
for(i = 299; a[i] == 0&&i > pos*n-1; i--);
while(i >= 0)
{
if(i == pos*n-1)
cout<<".";
cout<<a[i];
i--;
}
cout<<endl;
}
return 0;
}

求高精度幂(poj1001)的更多相关文章

  1. Poj.Grids 2951 浮点数求高精度幂

    2951:浮点数求高精度幂 总时间限制: 1000ms 内存限制: 65536kB 描述 有一个实数 R ( 0.0 < R < 99.999 ) ,要求写程序精确计算 R 的 n 次方. ...

  2. 求高精度幂(java)

    求高精度幂 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 对数值很大.精度很高的数进行高精度计算是一类十分常见的问题.比如,对国债进行计算就是属于这类问题. 现在要 ...

  3. 【ACM】求高精度幂

    题目来源:http://poj.org/problem?id=1001&lang=zh-CN 求高精度幂 Time Limit: 500MS   Memory Limit: 10000K To ...

  4. poj 1001 求高精度幂(Java, BigDecimal, pow, hasNext, stripTrailingZeros, toPlainString)

    求高精度幂 Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 180325   Accepted: 43460 Descripti ...

  5. Exponentiation(求高精度幂)

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 175340   Accepted: 42341 ...

  6. poj 1001 求高精度幂

    本题的测试用例十分刁钻,必须要考虑到很多的细节问题,在这里给出一组测试用例及运行结果: 95.123 12 548815620517731830194541.899025343415715973535 ...

  7. C# 高精度求幂 poj1001

    高精度求幂 public static char[] exponentiation(string a,int r) { ]; string b = ""; string c = a ...

  8. HDU 1402 A * B Problem Plus (FFT求高精度乘法)

    A * B Problem Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  9. 使用java求高精度除法,要求保留N位小数

    题目要求是高精度除法,要求保留N位小数(四舍五入),并且当整数部分为0时去除0的显示 import java.math.BigDecimal; import java.util.Scanner; pu ...

随机推荐

  1. SpringBoot 在CentOS7部署,注册为服务,开机启动

    1.首先在maven工程的pom文件中引入以下标签并保存 <build> <plugins> <plugin> <groupId>org.springf ...

  2. python学习笔记(九)之字符串

    定义字符串 >>> mystring = 'Hello Python' >>> name = str('Mountain') >>> mystri ...

  3. MSSQL 数据库性能优化

    优化数据库的注意事项: 1.关键字段建立索引. 2.使用存储过程,它使SQL变得更加灵活和高效. 3.备份数据库和清除垃圾数据. 4.SQL语句语法的优化. 5.清理删除日志. SQL语句优化的基本原 ...

  4. JS中的实例方法与静态方法

    一.静态方法与实例方法的例子: 我们先来看一个例子来看一下JS中的静态方法和实例方法到底是什么 静态方法: function A(){} A.sayMeS=function(){ console.lo ...

  5. 使用ubuntun16.04代码笔记

    (1)cd  /代表到根目录下面:ls表示将盘中内容列出:cd  /home表是打开根目录下的home文件夹:(注意:凡是根目录下的文件夹前面都要加 /) (2)快捷键方式:可以用tab自动补全 (1 ...

  6. 【JDK】JDK7与JDK8环境共存与切换:先安装jdk7,配置好环境变量后再安装jdk8

    1.先安装JDK7 下载jdk-7u79-windows-i586.exe,安装后配置好环境变量JAVA_HOME,CLASSPATH,PATH java -version javac 指令都正常 2 ...

  7. 【DeepLearning学习笔记】Coursera课程《Neural Networks and Deep Learning》——Week2 Neural Networks Basics课堂笔记

    Coursera课程<Neural Networks and Deep Learning> deeplearning.ai Week2 Neural Networks Basics 2.1 ...

  8. .gitignore 文件添加或更新后规则无效的解决方案

    项目已经提交之后,突然想忽略某个文件或目录 A,于是在 .gitignore 里添加了忽略规则.但是提交(commit)之后,发现一旦修改了 A,git 同样会检测到 A 的变化(changes) , ...

  9. windows7 能连接移动硬盘 无法显示盘符

    右键点我的电脑,管理里,点磁盘管理,看盘认到没,有时候认到了但是没给盘符,需要自己手动给一个

  10. 斯坦福开源无Bug的随机计算图Certigrad

    斯坦福开源无Bug的随机计算图Certigrad https://news.cnblogs.com/n/573690/ ttps://github.com/dselsam/certigrad