题目描述

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 R n 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.记录小数点的位置,
2.判断有无整数
3.去除无效的0;

#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
#define maxn 10000
#define INF 0x3f3f3f3f
using namespace std;
int b[maxn + 5];
int len;
void mul(int sum){int i;int add=0;  //相乘后增加的for(i = 0; i < len; i++){int term = b[i]*sum +add;b[i] = term%10;add = term/10;}while(add){b[i++] = add%10;add = add / 10;}len = i;   //记录len的长度
}
int main()
{char a[8];int n;while(scanf("%s %d",&a,&n)!=EOF){int p = 0, sum = 0;  //p记录小数点的位置,即小数点后面有几个小数for(int i = 0; i < strlen(a); i++){if(a[i] == '.'){p = (strlen(a) - i - 1)*n;}else {sum = sum*10 + a[i] - '0';//将字符串全部转化为整数形式}}b[0] = 1;len = 1;for(int i = 0; i < n; i++)mul(sum);cout<<len<<endl;if(len <= p){  //len小于p 说明没有整数部分printf(".");for(int i = 0; i < p - len; i++){printf("0");}int k = 0;while(b[k] == 0)k++;  //去掉无效的0for(int i = len - 1; i >= k; i--)printf("%d",b[i]);printf("\n");}else {  //len>p,说明有整数,int j = 0;while(b[j] == 0 && j < p)j++;//去除无效0for(int i = len - 1; i >= j; i--){if(i + 1 == p)printf(".");printf("%d",b[i]);}printf("\n");}}return 0;
}

N---Exponentiation相关推荐

  1. C++modular exponentiation模幂运算的实现算法(附完整源码)

    C++modular exponentiation模幂运算的实现算法 C++modular exponentiation模幂运算的实现算法完整源码(定义,实现,main函数测试) C++modular ...

  2. poj 1001 Exponentiation(java)

    点击打开链接 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 178771   Accepted: ...

  3. JAVA:实现binary exponentiation二进制幂运算算法(附完整源码)

    JAVA:实现binary exponentiation二进制幂运算算法 package com.thealgorithms.divideandconquer;public class BinaryE ...

  4. Proof (of knowledge) of exponentiation

    1. Proof of exponentiation Proof of exponentiation是基于adaptive root assumption(充分必要条件)的. 特别适合当 x x x很 ...

  5. Exponentiation

    Exponentiation is a mathematical operation, written as bn, involving two numbers, the base b and the ...

  6. POJ 1001 Exponentiation C++解题报告 JAVA解题报告

    求高精度幂 Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30980 Descripti ...

  7. 百炼1001: Exponentiation 解题

    链接:http://bailian.openjudge.cn/practice/1001/ 思路 乍一看是很简单的题目,但是答案必须高精度输出,因此需要手动实现一个高精度运算方法.如果直接使用int, ...

  8. HDU 1063 Exponentiation

    JAVA 水过 import java.io.*; import java.util.*; import java.math.*;public class aa {public static void ...

  9. 快速求幂(Quick Exponentiation)

    接触ACM没几天,向各路大神求教,听说ACM主要是研究算法,所以便开始了苦逼的算法学习之路.话不多说,RT所示,学习快速求幂. 在头文件<math.h>或是<cmath>中,d ...

  10. 【POJ - 1001 】Exponentiation (Java大数,高精度)

    题干: Problems involving the computation of exact values of very large magnitude and precision are com ...

最新文章

  1. Linux下遍历文件夹的实现
  2. 部署 YApi 接口管理服务
  3. vba获取通达信光标的坐标数据_「高阶应用」谈一下VB6和VBA的坐标系统
  4. 代码review工具:Review Board
  5. NVIDIA Physix Unity3D
  6. bgp通告四原则_华为路由器BGP路由选路和负载均衡
  7. java 正则表达式提取字符串
  8. 改变Linux的DNS解析顺序(DNS到hosts)
  9. html5 figure 标签
  10. ServletConfig对象--配置初始化参数以及获取初始化参数
  11. datagrid commandname
  12. linux下怎么打开bin文件怎么打开,怎么打开bin格式的文件
  13. 基于ricequant的lstm时间序列股价预测(pytorch)
  14. c php embed,使用PHP Embed SAPI实现Opcodes查看器
  15. 网络安全如何“疏而不漏”,了解一下锐捷大数据安全平台“降维攻击”
  16. HIR夏季挑战赛作品紧急优化
  17. 线下沙龙 | EOS入门及最新技术解读
  18. Extension 与主app共享数据
  19. 瀑布模型,快速原模型,螺旋模型,喷泉模型
  20. pr怎么渲染导出最小体积的高清视频?

热门文章

  1. 全球股市下跌潮蔓延 多个国家地区拟出手救市
  2. UDK游戏开发基础命令
  3. 博弈论重要算法:Sprague-Grundy 定理 (SRM 561 Div1 550)
  4. 1: 认识WPF和一个小Demon
  5. 当Shell遇上了NodeJS
  6. C#开发:openfiledialog的使用
  7. laravel配置加解密
  8. h5 移动端 监听软键盘弹起、收起
  9. 三十五岁后,就不能做软件测试了?
  10. (整理)REHL6.5_Yum安装Reids