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 < ...
随机推荐
- iOS动态运行时方法
在某些时候,程序可能需要根据获取的参数来决定调用的方法. 要实现这样的功能,就需要使用到动态运行时方法了. 首先需要定义好接口,以便调用. 然后就是动态调用定义好的方法. 这里有两种方法, 第一种: ...
- WCF初步学习
一.理解面向服务(Service-Oriented-Architecture) 是指为了解决在Internet环境下业务集成的需要,通过连接能完成特定任务的独立功能实体实现的一种软件系统架构.S ...
- 软件介绍:搜索工具 Listary
如今的互联网时代,搜索的重要性我想大家都是认可的.网上的知识浩如烟海,而搜索引擎是通向这些知识的入口.谷歌.百度等搜索引擎给我们带来了极大的便利,也无怪他们成长为如今的互联网巨头. 然而储存在个人硬件 ...
- vs2012新建项目产生的问题
当用vs新建web项目时遇到
- java中关于SSL/TSL的介绍和如何实现SSL Socket双向认证
一. SSL概述 SSL协议采用数字证书及数字签名进行双端实体认证,用非对称加密算法进行密钥协商,用对称加密算法将数据加密后进行传输以保证数据的保密性,并且通过计算数字摘要来验证数据在传 ...
- ADO知识的运用二(Day 28)
可能是最近有些沉迷于电视剧了,所以,好多天都没写总结了.我知道这样不好,但又老管不住自己,也许是我自控力太差了吧......呵呵,如果在不写总结,可能以后就会成为习惯了.所以今天要赶紧补上...... ...
- 在zendstudio上配置SVN
本文介绍zendstudio结合SVN的使用方法. 一.部署svn服务器 直接安装用svn软件,配置太过麻烦,用户和版本库.权限管理不太方便.推荐使用CollabNetSubversionEdge.以 ...
- .Net页面缓存OutPutCachexian详解
一 它在Web.Config中的位置 <system.web> <!--页面缓存--> <caching> <outputCacheSettings> ...
- 虚拟机NAT模式主机ping不通虚拟机解决方案
本篇没有抓包,只是简单一个实施.需要的童鞋可以拿走这个方法. 虚拟机与真机通信三种模式, 桥接模式,NAT 模式 ,HOST 模式. 桥接就是在真机的网络上模拟一个网卡,给虚拟机申请一个和真机在同一个 ...
- 公选网站作业4_2.php
序: 此实验的功能是只有已经登陆或者已经注册的用户才有发表留言的资格,否则只能够浏览留言. 1. 主要文件: 4_2login.html// 登陆的主页面 4_2login.php //处理登 ...