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 < ...
随机推荐
- 蓝桥杯之K好数问题
问题描述 如果一个自然数N的K进制表示中任意的相邻的两位都不是相邻的数字,那么我们就说这个数是K好数.求L位K进制数中K好数的数目.例如K = 4,L = 2的时候,所有K好数为11.13.20.22 ...
- [LeetCode][Python]15:3Sum
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 15: 3Sumhttps://oj.leetcode.com/problem ...
- Android UI学习组件概述
Android的UI组件繁多,如果学习的时候不能自己总结和分类而是学一个记一个不去思考和学习他们内在的联系那真的是只有做Farmer的命了.为了向注定成为Farmer的命运抗争,在学习Android的 ...
- OpenGL绘制简单场景,实现旋转缩放平移和灯光效果
本项目实现了用OpenGL绘制一个简单场景,包括正方体.球体和网格,实现了物体的旋转.缩放.平移和灯光效果.附有项目完整代码.有具体凝视.适合刚開始学习的人熟悉opengl使用. 开发情况 开发环境V ...
- Objective-C基础笔记(2)@property和@synthesize
先贴出使用@property和@synthesize实现的上一篇中的代码,再解释这两个keyword的使用方法和含义,代码例如以下: Person.h文件 #import <Foundation ...
- Myeclipse2014 SVN安装方法以及项目上传到svn服务器
1. 打开 Myeclipse 工具栏下的Help下的Install from Site 2.打开后弹出窗口, 并点击Add标签,如下图: 3.现在是最重要的一步,填写相关信息. 在对话框Name输入 ...
- android 监听 USB 拔插广播消息
USBBroadcastReceiver.java package com.example.communication; import android.content.BroadcastReceive ...
- poj 1469(二分图 最大匹配)
这道题让我认识到了c++cin,cout确实会使其超时,还是我用的c printf吧 #include<cstdio> #include<iostream> #include& ...
- Android入门——UI(2)
介绍SeekBar拖动条控件.ProgressBar进度条控件.DatePicker日历控件.TimePicker时间控件 <?xml version="1.0" encod ...
- 微信支付 v 3.3.6
文字说明: 前提:注册.申请服务号,开通微信支付. 涉及到的参数:AppId.AppSecret.原始ID(自动回复).mch_id(商户号).Key(商户密钥:自己设定.) 统一规范: 要求 认证方 ...