POJ 1001(Exponentiation)
来源:互联网 发布:美国网络存储公司 编辑:程序博客网 时间:2024/05/16 10:53
Exponentiation
Time Limit: 500MS Memory Limit: 10000KTotal Submissions: 79498 Accepted: 18840
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.
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 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
Hint
If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer
答案:s is a string and n is an integer
#include <stdio.h>#include <string.h>int result[126] = {0};//5 * 25 = 125int len;void mul (int a[], int n) {int i ;int add = 0;//相乘后增加的for ( i = 0; i < len; i++) {int term = a[i] * n + add;a[i] = term % 10;add = term / 10;}while (add) {a[i++] = add % 10;add = add / 10;}len = i;//长度可能有变化}int main () {char a[6];int a1, r;while (scanf("%s %d", a, &r) != EOF) {int position = 0, sum = 0, len1;//position记录小数点的位置len1 = strlen(a);for ( int i = 0; i < len1; i++) {//将浮点数转化为整数if (a[i] == '.') {position = (len1 - i - 1) * r;i++;}sum = sum * 10 + a[i] - 48;}result[0] = 1;len = 1;for (int i = 0; i < r; i++) {mul(result, sum);}//增加小数点if (len <= position) {printf(".");//补零for (int i = 0; i < position - len; i++) {printf("0");}int k = 0;//去掉无效0while (result[k] == 0) {k++;}for (int i = len - 1; i >= k; i--) printf("%d", result[i]);printf("\n");}else {int j = 0;// 去掉无效0while (result[j] == 0 && j < position) j++;for (int i = len - 1; i >= j; i--) {if (i + 1 == position)printf(".");printf("%d", result[i]);}printf("\n");}}}
Exponentiation
Time Limit: 500MS Memory Limit: 10000KTotal Submissions: 79498 Accepted: 18840
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.
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 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
Hint
If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer
s is a string and n is an integer
0 0
- POJ 1001 Exponentiation
- POJ 1001 Exponentiation
- poj 1001 Exponentiation
- POJ 1001 "Exponentiation"
- poj 1001 Exponentiation
- POJ 1001 Exponentiation
- poj 1001 exponentiation
- 【POJ】1001 Exponentiation
- POJ 1001 Exponentiation
- poj 1001Exponentiation
- 《POJ 1001》 Exponentiation
- POJ 1001 Exponentiation
- [POJ]1001 Exponentiation
- POJ-1001-Exponentiation
- [poj] 1001 Exponentiation
- POJ 1001 Exponentiation
- poj 1001 Exponentiation
- POJ-1001 Exponentiation 高精度
- Android之SDK如何更新
- 淘宝之HBase MapReduce实例分析
- 蓝牙的RSSI转换为信号强度百分百
- (素材源码)swanzhu学IOS(三)打飞机
- YTU 2892 免费看电影 贪心
- POJ 1001(Exponentiation)
- Linux 下面安装redis
- Seek the Name, Seek the Fame
- UVA-11000 Bee-蜜蜂繁殖
- 【XML】视频总结
- uvalive 3616
- java Math.floor,Math.ceil,Math.rint,Math.round用法详解
- POJ-2013 Symmetric Order-对称排列人名
- 验证邮箱是否存在原理