题目描述:

Exponentiation
Time Limit: 500MS   Memory Limit: 10000K
Total Submissions: 80517   Accepted: 19098
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
我的分析与总结:

基本问题1:数据的接收和存取:

运算因子超出了整型、实型能表示的范围,肯定不能直接用一个数的形式来表示。可选方案:数组和字符串。

1,推荐用字符串接收数据,然后把接收的字符转化为整形赋值到整型数组中。,

2,相乘时,做好数据的逆序处理,因为按照我们算的步骤,数据应该在数组中是逆序存储。

基本问题2:计算结果位数的确定

乘积的位数最大为两个因子的位数之和

乘法代码:(没看太懂)

#include <iostream>
using namespace std;
int main()
{
char r[]={''};//底数
int n=;//指数
while(cin>>r>>n)
{
int m[]={};
int b[]={};
int i,j,m_i;
int m_number=,m_data=;//小数点个数,每次相乘的数据
for(i=;i<;i++)//找到小数点的位置
{
if(r[i]=='.')
{
m_i=i;
break;
}
}
if(i==)//说明没有小数点
{
j=;
while(r[j]=='')
{
r[j]='a';
j++;
}
m_number=;
}
else//说明有小数点
{
i=;
while(i<m_i&&r[i]=='')//小数点之前前导0处理为-1
{
r[i]='a';
i++;
}
i=;
while(i>m_i&&(!r[i]||r[i]==''))//小数点之后的后缀零处理
{
r[i]='a';//赋值为a
i--;
}
for(i=;i>=;--i)
{
if(!r[i]||r[i]=='a')continue;
if(r[i]=='.')break;
m_number++;//判断有多少小数
}
}
for(i=,j=;i<;++i)
{
if(r[i]=='a')continue;
if(r[i]=='.')continue;
if(!r[i])continue;
b[j]=(int)(r[i]-'');//转成int的b
j++;
}
while(j<)
{
b[j]=-;
j++;
}//b可以弄出实数来了
for(i=;i<;++i)
{
if(b[i]==-)continue;
m_data=m_data*+b[i];//相乘的大数
}
for(j=,i=-;j>=&&i>=;--j)
{
if(b[j]==-)continue;
else
{
m[i]=b[j];//赋值给m
i--;
}
}
m_number=m_number*n;
n--;
while(n--&&i!=)//如果出现输入都是0
{
for(j=i+;j<;j++)//有这么多位
{
int tem=m[j]*m_data;//每一位与数相乘
m[j]=;
if(tem==)m[j]=;
else
{
int t=j;
while(tem/!=||tem%!=)
{
m[t]=m[t]+tem%;//将每一位都分离出来存放在不同的单元
int tt1=t;
while(m[tt1]>)//对超过9的处理
{
int tem2=m[tt1];
m[tt1]=tem2%;//得到这位的数据
tt1--;
m[tt1]=m[tt1]+tem2/;//往前加进的位数
}
t--;
tem=tem/;
}
}
}
i=;
while(m[i]==)i++;//找到m中第一个非零的位置
i--;
}
i=;
while(i<&&m[i]==)
i++;
if(m_number==)//对没有小数点的处理
{
if(i==)cout<<<<endl;
else
{
for(;i<;++i)cout<<m[i];
cout<<endl;
}
}
else//有小数点的处理
{
if(m_number>-i)//250-i表示在i之前有i个零,有250-i个非零
{//小数点超过相乘得到的实数,则补零
cout<<".";
while(m_number-->-i)
cout<<;
for(;i<;i++)
cout<<m[i];
cout<<endl;
}
else
{
for(;i<;++i)
{
if(m_number==-i)cout<<".";//包含处理等于
cout<<m[i];
}
cout<<endl;
}
}
}
return ;
}

北京大学1001ACM——高精度类型题总结的更多相关文章

  1. uva 748 Exponentiation 浮点数乘方运算 高精度水题

    输入的前六位数表示一个小数,然后输入一个数表示几次方.要求用高精度算出结果. 高精度水题,主要注意处理小数点,先在输入时把小数点提取出来并记录位置,用普通乘法计算出结果后由后向前计算位置添加小数点. ...

  2. leetcode 字符串类型题

    1,Vaild Palindrome bool isPalindrome(string& s) { transform(s.begin(), s.end(), s.begin(), tolow ...

  3. java 笔记(1)-—— JVM基础,内存数据,内存释放,垃圾回收,即时编译技术JIT,高精度类型

    1.java中5个存放数据的地方: (1).寄存器(Registers):位于CPU内部,是速度最快的存储区,但是数量和容量有限.在java中不能直接操作寄存器. (2).栈(Stack):栈位于通用 ...

  4. hdu 2987最大权闭合图模板类型题

    /* 最大权闭合图模板类型的题,考验对知识概念的理解. 题意:如今要辞退一部分员工.辞退每个员工能够的到一部分利益(能够是负的),而且辞退员工,必须辞退他的下属.求最大利益和辞退的最小人数. 最大权闭 ...

  5. leetcode 链表类型题总结

    链表测试框架示例: // leetcodeList.cpp : 定义控制台应用程序的入口点.vs2013 测试通过 // #include "stdafx.h" #include ...

  6. 高精度水题(POJ2109)

    题目链接:http://poj.org/problem?id=2109 double 可以虽然可以表示10^-307~~~10^208,但是精确度只有16位,这个题有bug. #include < ...

  7. leetcode 动态规划类型题

    1,Triangle int mininumTotal(vector<vector<int>>& triangle) { ; i >= ; --i) { ; j ...

  8. 【高精度&想法题】Count the Even Integers @ICPC2017HongKong/upcexam5563#Java

    时间限制: 1 Sec 内存限制: 128 MB Yang Hui's Triangle is defined as follow. In the first layer, there are two ...

  9. leetcode 树类型题

    树的测试框架: // leetcodeTree.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...

随机推荐

  1. linux pthread_cond_signal

      pthread_cond_signal函数的作用是发送一个信号给另外一个正在处于阻塞等待状态的线程,使其脱离阻塞状态,继续执行.如果没有线程处在阻塞等待状态,pthread_cond_signal ...

  2. Windows 下 把EXE 程序变成服务运行

    1. 下载  instsrv.exe 和 srvany.exe   我下载的地址  [点击打开链接][https://www.cr173.com/soft/64394.html] 2. cmd  cd ...

  3. Matlab图像处理——中值滤波medfilt2问题解决

    本文链接:https://blog.csdn.net/Pxzly1117/article/details/79201772程序: I=imread('13.jpg');%读入图像imshow(I);h ...

  4. OpenJudge计算概论-最长单词2

    /*======================================================================== 最长单词2 总时间限制: 1000ms 内存限制: ...

  5. 腾讯基于 Flink 的实时流计算平台演进之路

    https://mp.weixin.qq.com/s/MGnG_Mpf6CUQWLJHvmWqLA

  6. HTML5 地理位置定位API(2)

    HTML5 Geolocation API (地理位置应用程序接口) 目前PC浏览器支持情况: Firefox 3.5+Chrome 5.0+Safari 5.0+Opera 10.60+Intern ...

  7. 阶段5 3.微服务项目【学成在线】_day17 用户认证 Zuul_14-网关-介绍网关及搭建网关工程

    4 Zuul网关 4.1 需求分析 网关的作用相当于一个过虑器.拦截器,它可以拦截多个系统的请求. 本章节要使用网关校验用户的身份是否合法. 4.2 Zuul介绍 什么是Zuul? Spring Cl ...

  8. jenkins:构建机器为windows,部署机器为linux

    备份老的jar包 d=`date +"%Y%m%d-%H%M%S"` cd /home/eccore/app/uat -SNAPSHOT.jar steward-api--SNAP ...

  9. 渡鸦币(Raven)钱包交叉编译详解

    1 环境准备 1.1 准备Ubuntu 准备虚拟机或物理机,操作系统为Ubuntu 16.04 1.2 安装Mingw sudo apt-get install g++-mingw-w64-i686 ...

  10. IdentityServer4学习笔记汇总(实现传送门在底部)

    前言 互联网时代,对信息和资源的保护越发苛刻,在所有应用中授权和认证是必不可少缺少的一部分.如果一个应用没有授权和认证那么这个应用就是不完整或者说不安全的应用.在.Net平台给我们提供了一套完整的授权 ...