题目描述

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. NIPS 2017上演:Google大神们将带来哪些「精彩」?
  2. Azure实践系列 1:部署和基本配置Azure AD
  3. 每日一皮:完美的结对编程!
  4. java 多线程 day12 读写锁
  5. 看懂堆排序——堆与堆排序(三)
  6. 算法系列之赫夫曼树的精解【构造流程及原理分析】
  7. Python Day28
  8. ELK日志系统的写入优化
  9. 京东面试官:呦,你对中间件 Mycat了解的还挺深~
  10. (lucas) Saving Beans
  11. 为什么微软要推 ADO.NET Data Services
  12. 融完5亿美元创始人出局?腾讯投资的明星无人车公司Zoox地震了
  13. 从事测试的第6年 , 开工第二天五千字总结..我不平凡的2021
  14. 怎么在大数据里面删除不了_数据库删除大数据怎么操作
  15. 怎么把柱形图和折线图放在一起_excel怎么把柱状图和折线图合并
  16. 双币对冲外汇ea ,单货币对冲策略, EA运行原理
  17. MATLAB Appdesigner开发独立桌面App全流程(一):以打开串口功能为例介绍Appdesigner的基本使用
  18. 非同帆响-得帆信息发布全新高生产力PaaS平台,重新定义企业软件生产力
  19. 任正非千金买马骨:与李一男戏剧性恩怨情仇
  20. react报错解决 Rendered more fewer hooks than during the previous render

热门文章

  1. 规则2 使用内容发布网络
  2. [转]JavaScript继承详解
  3. WindowsXP 下搭建PHP环境(笔记)
  4. [原]部署kubernetes dashboard(二)
  5. js操作符类型转换大全
  6. 采集post传输的数据
  7. 简单的跑马灯效果(轮播图)
  8. (转)对各种初始化函数的理解:OnInitDialog、InitInstance、InitApplication函数的理解...
  9. IOS发送带附件的邮件
  10. Kinetic使用注意点--circle