POJ1001·Exponentiation
来源:互联网 发布:屏幕录制软件免费版 编辑:程序博客网 时间:2024/06/09 20:31
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 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.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 <stdio.h>#include <iostream>#include <string>using namespace std;int main(){string mlp;//乘数int power;//乘数的幂int r[151];//保存结果int hdot;//保存小数点位置 while(cin>>mlp>>power){hdot=0;for(int t=0;t<150;t++)//初始化结果数组 {r[t]=-1;}if(mlp.find(".")!=string::npos)hdot=mlp.length()-mlp.find(".")-1;//记录小数点位置 string::iterator itr=mlp.end()-1;//迭代器指向最后一个字符 while(hdot>0&&itr>=mlp.begin())//去掉末尾无效的0 {if(*itr!='0'){break;}hdot--;itr--;}int cn=0;while(itr>=mlp.begin())//乘数第一次向结果数组中赋值 {if(*itr!='.'){r[cn]=*itr-'0';cn++;//结果数组长度或者说位数 }itr--;}int k=cn-1;int m=0;//保存临时数while(k>-1){m=m*10+r[k];//乘数的逆序??? k--;}for(int i=1;i<power;i++)//计算指数次方,方法很巧妙,自叹不如 {int j=0;while(r[j]>-1){r[j]=r[j]*m;j++;}j=0;while(r[j]>-1){if(r[j+1]==-1&&r[j]>=10)r[j+1]=r[j]/10;elser[j+1]+=r[j]/10;r[j]=r[j];j++;}} hdot=hdot*power;//寻找小数点位置 int cnt=0;while(r[cnt]>-1){cnt++;}if(hdot>=cnt){cout<<".";while(hdot>cnt){cout<<"0";hdot--;}hdot=0;}for(k=cnt-1;k>=0;k--){if((k+1)==hdot&&hdot!=0)cout<<".";cout<<r[k];}cout<<endl;}return 0;}
- POJ1001·Exponentiation
- POJ1001 Exponentiation
- POJ1001 Exponentiation
- POJ1001 Exponentiation
- POJ1001 Exponentiation
- POJ1001:Exponentiation
- 【poj1001】 Exponentiation
- POJ1001 Exponentiation
- POJ1001 Exponentiation
- poj1001 Exponentiation
- poj1001——Exponentiation
- poj1001 Exponentiation 小数幂
- POJ1001 Exponentiation 高精度乘法
- POJ1001 Exponentiation 高精度
- POJ1001 Exponentiation,高精度乘法
- POJ1001 Exponentiation (解题报告)
- poj1001 Exponentiation --高精度
- poj1001 Exponentiation 解题报告
- ejb学习总结
- POJ1000·A+B Problem
- MySQL日期时间函数大全
- Android4.0源码下载与编译
- sql存储过程
- POJ1001·Exponentiation
- Netfilter的rpfilter技术-Linux的uRPF
- 外网访问Vmware虚拟机中的某个服务(如http)
- Gearman一个异步任务调度器
- 显示指定目录的目录结构
- POJ1002·487-3279
- HTML5教程专题
- Java中的字符串 String, StringBuffer和StringBuilder
- Netfilter策略路由和uRPF