http://poj.org/problem?id=1001
来源:互联网 发布:淘宝二手回收骗局 编辑:程序博客网 时间:2024/06/16 10:22
Exponentiation
Time Limit: 500MS Memory Limit: 10000KTotal Submissions: 134006 Accepted: 32768
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
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int res[200];char s[20];char zheng[10];char xiao[10];char temp[200];int x;int r;int xiaowei;int cnt;int main() { while (scanf("%s %d", s, &r)!=EOF) { for (int i = 0; s[i] != '\0'; i ++) { if (s[i] == '.') s[i] = ' '; } sscanf(s,"%s%s", zheng, xiao); for (int i = strlen(xiao)-1; i >= 0; i --) { if (xiao[i] == '0') { xiao[i] = '\0'; } else { break; } } xiaowei = strlen(xiao); xiaowei *= r; x = 0; for (int i = 0; zheng[i] != '\0'; i ++) { x *= 10; x += zheng[i]-'0'; } for (int i = 0; xiao[i] != '\0'; i ++) { x *= 10; x += xiao[i]-'0'; } cnt = 0; int t = x; while (t) { res[cnt ++] = t%10; t /= 10; } for (int i = 1; i < r; i ++) { for (int j = 0; j < cnt; j ++) { res[j] *= x; } int c =0; for (int j = 0; j < cnt; j ++) { res[j] += c; c = res[j] / 10; res[j] = res[j] % 10; } while (c) { res[cnt ++] = c % 10; c /= 10; } } if (xiaowei == 0) { for (int i = cnt-1; i >= 0; i --) { printf("%d", res[i]); } printf("\n"); continue; } int c_cnt = 0; int flag = 0; for (int i = 0; i < cnt; i ++) { if (i != xiaowei) { temp[c_cnt ++] = '0' + res[i]; } else { temp[c_cnt ++] = '.'; temp[c_cnt ++] = '0' + res[i]; flag = 1; } } if (!flag) { for (int i = cnt; i < xiaowei; i ++) { temp[c_cnt ++] = '0'; } temp[c_cnt ++] = '.'; temp[c_cnt] = '\0'; } for (int i = c_cnt-1; i >= 0; i --) { printf("%c", temp[i]); } printf("\n"); }return 0;}
0 0
- http://poj.org/problem?id=1001
- http://poj.org/problem?id=2965
- http://poj.org/problem?id=2075
- http://poj.org/problem?id=1125
- http://poj.org/problem?id=2983
- http://poj.org/problem?id=2406
- http://poj.org/problem?id=1961
- http://poj.org/problem?id=1486
- http://poj.org/problem?id=1062
- http://poj.org/problem?id=2983
- http://poj.org/problem?id=3159
- http://poj.org/problem?id=1201
- http://poj.org/problem?id=3259
- http://poj.org/problem?id=3233
- http://poj.org/problem?id=1273
- http://poj.org/problem?id=3281
- http://poj.org/problem?id=1007
- http://poj.org/problem?id=1840
- Python中下划线---完全解读
- ACM斗牛游戏算法JAVA实现
- Zend studio快捷键使用
- 密码改变人生
- 1407291736-hd-Lowest Common Multiple Plus.cpp
- http://poj.org/problem?id=1001
- 现在网站太无趣了
- struts2.1.8+hibernate3.2+Spring3.0+ExtJs4.2+MySql+WebSocket 更新
- IOS编程之通讯录
- 关于GET和POST请求
- 将数据库表导出到excel中
- VS 2010下 打开实例 出现这样的错误: LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- 手把手教你玩转网络编程模型之完成例程(Completion Routine)篇(上)
- sparkPi在yarn模式下运行