【POJ】 1001 Exponentiation 大数
2016-12-13 22:28
375 查看
POJ 1001 Exponentiation
DescriptionProblems 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
大数问题,麻烦,当做整数(去除小数位末尾的零)的乘方主要是及小数什么时候输出
#include<stdio.h> #include<string.h> const int MAX=1000,M=100000000; long long A[MAX]; int flag(char *p,int l) { int i;for(i=0;i<l;i++) if(p[i]=='.') return i+1; return i+1; } void print(long long a,int l) { if(!a) return ; print(a/10,--l); if(!l) printf("."); printf("%lld",a%10); } int main() { int i,a,b,n;char s[10]; while(scanf("%s%d",s,&n)!=EOF) { //b=s;b=s的整数部分; int lenf=strlen(s);b=0; int lenz=flag(s,lenf); if(lenz<lenf) { for(i=lenf-1;s[i]=='0';i--,lenf--); for(a=i=0;i<lenz-1;i++) a=a*10+s[i]-'0'; for(i=lenz;i<lenf;i++) a*=10,b=b*10+(s[i]-'0'); }else { for(a=i=0;i<lenz-1;i++) a=a*10+s[i]-'0'; } lenf-=lenz; int t=0,k=lenf;long long c=0; lenf*=n;//记录小数位长度 A[0]=a=a+b;n--; while(n--) { for(c=i=0;i<=t;i++) A[i]=a*A[i]+c,c=A[i]/M,A[i]%=M; if(c) A[i]=c,t=i; } int len=8*t;//c=A[t]; c=A[t]; while(c) len++,c=c/10; if(lenf>=len) { printf("."); for(i=0;i<lenf-len;i++) printf("0"); } print(A[t],lenf); //printf("%lld",A[t]); for(i=t-1;i>=0;i--) { if(i*8<lenf&&lenf<=(i+1)*8) { int m=(i+1)*8-lenf;long long gg[8]; for(int g=7;g>=0;g--) gg[g]=A[i]%10,A[i]/=10; for(int g=0;g<8;g++) { if(g==m) printf("."); printf("%lld",gg[g]); } } else printf("%0.8lld",A[i]); } printf("\n"); } return 0; }
相关文章推荐
- poj 1001 Exponentiation 大数大数
- POJ 1001 Exponentiation (高精度/大数乘法)
- POJ-1001-Exponentiation-大数乘法
- POJ 1001 Exponentiation 无限大数的指数乘法 题解
- [转]POJ 1001 Exponentiation Java大数处理高精度小数
- POJ 1001 Exponentiation(大数)
- POJ 1001 Exponentiation 无限大数的指数乘法 题解
- poj 1001 -- Exponentiation (大数计算,模拟)
- POJ 1001 Exponentiation(大数处理)
- POJ 1001-Exponentiation(NYOJ 155 求高精度幂):大数问题
- POJ 1001-Exponentiation(NYOJ 155 求高精度幂):大数问题
- hdu_1063,poj_1001_Exponentiation(大数,高精度) nyoj_155_求高精度幂
- Exponentiation(POJ-1001) Java大数例题
- HDU 1063 && POJ 1001 Exponentiation (JAVA浮点数大数)
- POJ 1001 Exponentiation(大数幂Java实现)
- POJ 1001 Exponentiation&&NYOJ 155 求高精度幂
- POJ1001--Exponentiation(幂计算)翻译
- poj 1001 Exponentiation(高精度运算)
- poj 1001 Exponentiation
- POJ 1001 "Exponentiation"