时隔半年,终于AC了,加油!
#include <iostream>
#include <stdlib.h>
using namespace std;
void multi(int *, int *, int[]);
int main(){
int a[100];
int b[100];
int c[100];
char s[100];
int n;
while(cin >> s >> n){
for(int i = 0; i < 100; ++ i) a[i] = b[i] = 0;
for(int i = 0; i < 100; ++ i) c[i] = 0;
int p = 0;
for(int i = 0; i < strlen(s); ++ i){
if(s[strlen(s) - i - 1] != '.'){if(!p)a[i] = b[i] = (int) (s[strlen(s) - i - 1] - '0');else a[i - 1] = b[i - 1] = (int) (s[strlen(s) - i - 1] - '0');}else p = i * n;
}
for(int i = 0; i < n - 1; ++ i){
multi(a, b, c);
for(int i = 0; i < 100; ++ i) {a[i] = c[i]; c[i] = 0;}
}
int j;
int e;
for(e = 0; e < 100; ++ e)if(a[e] != 0 || e == p) break;
for(j = 99; j > -1; --j) if(a[j] != 0) break;
if(e- 1 >= j){printf("0\n"); continue;}
for(int i = 0; i < p - j; ++ i)if(i == 0)printf(".");else printf("0");
for(int i = j; i > e - 1; -- i) if(i != p)printf("%d", a[i]);else if(i > e) printf("%d.", a[i]);else printf("%d", a[i]);printf("\n");}
getchar();getchar();
}
void multi(int a[], int b[], int c[]){
for(int i = 0; i < 100; ++ i){
for(int j = 0; j < 100; ++ j){
c[i + j] += a[i] * b[j];
}
}
for(int i = 0; i < 100; ++ i){
c[i + 1] += c[i] / 10;
c[i] %= 10;
}
}
分享到:
相关推荐
如题所示,亲测可用。求高精度幂,不会的同学可以参考下,会做的同学可以给挑挑毛病!大家以代码会友!
poj 1001 Exponentiation用字符串操作的
业余爱好。所以,算法不一定好,CODING也不一定佳,效率不一定高,只是能通过online judge而已。
POj 1001源代码——高精度乘单精度POj 1001源代码——高精度乘单精度POj 1001源代码——高精度乘单精度POj 1001源代码——高精度乘单精度
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....
用java的biginteger实现的poj1001,比较简单的方法
简单地poj1001代码,是典型的利用数组输出结果的方法,关键的是测试数据。
2遍dp poj_3613解题报告 poj_3613解题报告
poj 1001答案
poj1001源码,c语言版,通过ac,包含注释,容易懂
自己写得大数浮点数幂运算(c++实现),系poj acm 的problem:1001的实现
北大POJ1001-Precision power 解题报告+AC代码
北京大学ACM详解poj1001, 内容很充实。
对数值很大、精度很高的数进行高精度计算是一类十分常见的问题。比如,对国债进行计算就是属于这类问题。 现在要你解决的问题是:对一个实数R( 0.0 ),要求写程序精确计算 R 的 n 次方(Rn),其中n 是整数并且 0 。
acm 1001 到1009代码,已通过验证
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
用递推方法+高精度算法,解决了poj1832 的连环锁问题,时间32ms。。。。。。
人们熟悉的四则运算表达式称为中缀表达式,例如(23+34*45/(5+6+7))。在程序设计语言中,可以利用堆栈的方法把中缀表达式转换成保值的后缀表达式(又称逆波兰表示法),并最终变为计算机可以直接执行的指令,得到...