ACM学习
2016-04-27 22:27
274 查看
题目1
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
answer
#include <iostream> #include <string> #include <vector> using namespace std; class power { friend istream& operator>>(istream& In, power& r); public: string operator()(int n); private: vector<int> s; int dot; }; istream& operator>>(istream& In, power& r) { string tmp; In >> tmp; for(int i=0; i!=6; ++i) if(tmp[i]=='.') r.dot=6-i-1; r.s.clear(); for(int i=5; i>=0; --i) if(tmp[i]!='.') r.s.push_back(tmp[i]-'0'); return(In); } string power::operator()(int n) { vector<int>answer(n*5); answer[0]=1; for(int i=0; i!=n; ++i) { vector<int>tmp(answer); for(int j=0; j!=n*5; ++j)answer[j]=0; for(int j=0; j!=n*5; ++j) for(int k=0; k!=5; ++k) answer[j+k]+=tmp[j]*s[k]; for(int j=1; j!=n*5; ++j) { answer[j]+=answer[j-1]/10; answer[j-1]%=10; } } string str; str.clear(); for(int i=0; i!=n*5; ++i)str=(char)(answer[i]+'0')+str; str.insert(n*5-dot*n, 1, '.'); while(str[0]=='0')str.erase(str.begin()); while(str[str.size()-1]=='0')str.erase(str.end()-1); if(str[str.size()-1]=='.')str.erase(str.end()-1); return(str); } int main() { power s; int n; while(cin >> s >> n) cout << s(n) << endl; }
相关文章推荐
- cocos2d-x知识总结
- HDU 2017
- ACM刷题之Codeforces———— Little Artem and Grasshopper
- iOS 多线程知识梳理
- linux内存管理--分配内存页(快速) get_page_from_freelist
- java_Scanner、Random
- zabbix常用术语
- Android多线程加速下载
- 设计模式之Iterator(二)
- linux内存管理--伙伴系统分配内存准备工作
- CRM系统之Salesforce 销售订单trigger
- SNR
- mysql_fetch_assoc查询多行数据
- 打印1到最大的n位数
- java 23种常用设计模式关系图
- 高效的jQuery
- __get_free_pages
- 浅谈JV内存结构
- linux内核源码分析(内存管理)--之数据结构
- 线性表