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 < ...
随机推荐
- BZOJ 1143 [CTSC2008]祭祀river(二分图匹配)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1143 [题目大意] 给出一张有向图,问最大不连通点集,连通具有传递性 [题解] 我们将 ...
- [Leetcode][Python]36: Valid Sudoku
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 36: Valid Sudokuhttps://oj.leetcode.com ...
- js 事件之 createEvent、dispatchEvent
//document上绑定自定义事件ondataavailable document.addEventListener('customevent', function(event) { alert(e ...
- Mac 上开启一个简单的服务器
终端输入命令: python -m SimpleHTTPServer 会开启一个端口为8000的本地服务器.
- uva10617 - Again Palindrome(dp)
再次回文 输入:标准输入 输出:标准输出 时间限制: 2秒 是àpalindorme的读取相同的从左边,因为它从右侧的一个或多个字符的序列.例如,Ž,TOT和女士的 回文,但是,ADAM是不是. 给定 ...
- JavaScript之面向对象学九(原型式继承和寄生式继承)
一.原型式继承 该继承模式是由道格拉斯*克罗克福德在2006年提出的实现继承的方法. 模式的基本思路:借助原型可以基于已有的对象创建新的对象,同时还不必因此创建自定义类型. 代码如下: functio ...
- JavaScript之共享onload
我们知道,当我们将JS代码脚本放到<head></head>标签之间时,这是的js代码加载要先于DOM加载,而我们往往会在JS代码脚本中写一些获取DOM元素的代码,而此时的DO ...
- C++ Member Functions的各种调用方式
[1]Nonstatic Member Functions(非静态成员函数) C++的设计准则之一就是:nonstatic member function至少必须和一般的nonmember funct ...
- R与数据分析旧笔记(十七) 主成分分析
主成分分析 主成分分析 Pearson于1901年提出的,再由Hotelling(1933)加以发展的一种多变量统计方法 通过析取主成分显出最大的个别差异,也用来削减回归分析和聚类分析中变量的数目 可 ...
- Material Design 开发利器:Android Design Support Library 介绍
转自:https://blog.leancloud.cn/3306/ Android 5.0 Lollipop 是迄今为止最重大的一次发布,很大程度上是因为 material design —— 这是 ...