Exponentiation
Time Limit: 500MS   Memory Limit: 10000K
Total Submissions: 138526   Accepted: 33859

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

{

...

}
遥远时代的第一道题,真是怀念啊,才学C语言的我明白了高精的意义
#include<iostream>
#include <string>
using namespace std;
string multiply(string a,string d){
int remain=0,temp=0;
string ad,mul="0";
for(int i=a.length()-1;i>=0;i--){
remain=0;//余数
ad="";//每次的乘积
for(int j=d.length()-1;j>=0;j--){
temp=(a[i]&15)*(d[j]&15)+remain;
remain=temp/10;
temp%=10;
ad=(char)(temp+'0')+ad;
}
if(remain){
ad=(char)(remain+'0')+ad;
}
int x=ad.length()-1;
int y=mul.length()-(a.length()-i);
remain=0;
while(x>=0&&y>=0){//完成加和
temp=(ad[x]&15)+(mul[y]&15)+remain;
remain=temp/10;
temp%=10;
mul[y]=temp+'0';
x--;y--;
}
while(x>=0){//如果ad串更长
temp=(ad[x]&15)+remain;
remain=temp/10;
temp%=10;
mul=(char)(temp+'0')+mul;
x--;
}
while(y>=0){//如果mul串更长
temp=(mul[y]&15)+remain;
remain=temp/10;
temp%=10;
mul[y]=temp+mul[y];
y--;
}
if(remain){//如果还有余数
mul=(char)(remain+'0')+mul;
}
}
return mul;
}
int main(){
string a,d;
int n;
while(cin>>a>>n){
int pos =a.find_first_of('.');//寻找小数点位置
a.erase(pos,1);
int num=(a.length()-pos)*n;
d=a;
for(int i=1;i<n;i++){
d=multiply(d,a);
}
if(pos==a.npos){//如果没有找到,a是整数,运算不会出现点,可以直接输出
for(int i=0;i<d.length()-1;i++){
if(d[0]!='0'){break;}
d.erase(0,1);
}
cout<<d<<endl;
continue;
}
d.insert(d.length()-num,".");
for(int i=0;i<d.length();i++){//去除前导零
if(d[0]!='0')break;
d.erase(0,1);
}
for(int i=d.length()-1;i>=0;i--){//去除后置零
if(d[i]!='0')break;
d.erase(i,1);
}
if(d[d.length()-1]=='.'){//没有小数部分就不用输出.
d.erase(d.length()-1,1);
}
cout<<d<<endl;
}
return 0;
}

  


poj 1001 Exponentiation 第一题 高精度 乘方 难度:1(非java)的更多相关文章

  1. POJ 1001 Exponentiation(大数运算)

    POJ 1001 Exponentiation 时限:500 ms   内存限制:10000 K 提交材料共计: 179923   接受: 43369 描述:求得数R( 0.0 < R < ...

  2. [POJ 1001] Exponentiation C++解题报告 JAVA解题报告

        Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30 ...

  3. POJ 1001 Exponentiation 无限大数的指数乘法 题解

    POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...

  4. POJ 1001 Exponentiation(JAVA,BigDecimal->String)

    题目 计算实数a的n次方,具体输出格式看案例 import java.util.*; import java.math.*; public class Main { public static voi ...

  5. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  6. POJ 1001 Exponentiation

    题意:求c的n次幂……要求保留所有小数…… 解法:一开始只知道有BigInteger……java大数+模拟.第一次写java大数……各种报错各种exception……ORZ 没有前导0和小数后面的补位 ...

  7. POJ 1001 Exponentiation 模拟小数幂

    模拟小数幂 小数点位 pos 非零末位 e 长度 len 只有三种情况 pos > len pos < e e < pos < len #include <iostrea ...

  8. POJ 1293 网络流 第一题

    完全的模板,做多了就好了吧 反向流量真的很有意思,有这样一种说法比较容易理解.”正向是+,反向就是-,其实是等价的.因为每次找到的增广路不一定是最优解里面的,所以再进行后面的操作的时候要重新选择,而反 ...

  9. 快速切题 sgu 111.Very simple problem 大数 开平方 难度:0 非java:1

    111.Very simple problem time limit per test: 0.5 sec. memory limit per test: 4096 KB You are given n ...

随机推荐

  1. Uvalive 7037 The Problem Needs 3D Arrays(最大密度子图)

    题意:给一段子序列,定义密度:子序列中的逆序对数/子序列的长度 求这个序列的对大密度. 分析:将序列中的每个位置视作点,逆序对\(<i,j>\)之间表示点i与点j之间有一条无向边.所以就转 ...

  2. [转]Algolia的分布式搜索网络架构

    转自:http://www.csdn.net/article/2015-03-11/2824176-the-architecture-of-algolias-distributed-search-ne ...

  3. tensorflow训练自己的数据集实现CNN图像分类2(保存模型&测试单张图片)

    神经网络训练的时候,我们需要将模型保存下来,方便后面继续训练或者用训练好的模型进行测试.因此,我们需要创建一个saver保存模型. def run_training(): data_dir = 'C: ...

  4. Jmeter使用流程及简单分析监控(转载)

    转载自:https://www.cnblogs.com/linglingyuese/archive/2013/03/04/linglingyuese-one.html#undefined 一.安装Jm ...

  5. java之继承中的构造方法

    继承中的构造方法  1.子类的构造过程中必须调用其基类的构造方法. 2.子类可以在自己的构造方法中使用super(argument_list)调用基类的构造方法. 2.1.使用this(argumen ...

  6. Nginx将不同IP的请求分发到不同的WEB服务器

    server { listen ; server_name localhost; large_client_header_buffers 16k; client_max_body_size 300m; ...

  7. APP接口版本不兼容怎么办? 教你一招

    现在基本每个公司都做APP,所以大家都面临 APP接口版本兼容的问题. iOS和android 要不断开发新版本,很多服务端开发都是在以前接口的逻辑上进行修改.新的APP和接口开发后,接口如何兼容老的 ...

  8. Visual Studio 2010生成解决方案时,导致C盘空间越来越小

    为了从根本上解决问题,还是去掉智能跟踪选项吧,方案: VS2010-->工具-->选项-->IntelliTrance-->将“启用IntelliTrace”勾选去掉--> ...

  9. SpringMVC HttpMessageConverter 匹配规则

    以下内容,如有问题,烦请指出,谢谢! SpringMVC启动时会自动配置一些HttpMessageConverter,接收到http请求时,从这些Converters中选择一个符合条件的来进行Http ...

  10. [Hdu6315]Naive Operations

    题意:给定一个初始数组b和一个初始值全部为0的数组a,每次操作可以在给定的区间(l,r)内让a[i](l=<i<=r)加一,或者查询区间区间(l,r)中a[i]/b[i](l=<i& ...