POJ 1001 Exponentiation 模拟小数幂
2016-08-13 12:38
429 查看
模拟小数幂
小数点位 pos
非零末位 e
长度 len
只有三种情况
pos > len
pos < e
e < pos < len
小数点位 pos
非零末位 e
长度 len
只有三种情况
pos > len
pos < e
e < pos < len
#include <iostream> #include <cstring> using namespace std; int a[500], b[500], c[500]; void Cal() { memset(c, 0, sizeof(c)); for(int i = 0; i < 200; i++) for(int j = 0; j < 10; j++) c[i+j] += a[i] * b[j]; for (int i = 0; i < 200; i++){ c[i+1] += c[i]/10; c[i] %= 10; } memset(a, 0, sizeof(a)); for (int i = 0; i <= 200; i++) a[i] = c[i]; } char s[10]; int pos, n, len; int main() { while(cin>>s>>n) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); int t = 0; for (int i = 5; i >= 0; i--) { if(s[i]=='.') pos = i; else b[t++] = s[i] - '0'; } a[0] = 1; for(int i = 1; i <= n; i++) Cal(); len = 200; while(!c[len] && len>=0) len--; int e = 0;//末尾 while(!c[e] && e<= len) e++; pos = 5 - pos; pos *= n;//小数点 if(pos > len) { cout<<"."; for (int i = pos-1; i >= e; i--) cout<<c[i]; cout<<endl; } else if(pos <= e)//整数 { for (int i = len; i >= pos; i--) cout<<c[i]; cout<<endl; } else//普通 { for (int i = len; i >= pos; i--) cout<<c[i]; cout<<"."; for (int i = pos-1; i >= e; i--) cout<<c[i]; cout<<endl; } } }
相关文章推荐
- [转]POJ 1001 Exponentiation Java大数处理高精度小数
- POJ 1001 Exponentiation 高精度小数相乘
- poj 1001 uva 748 Exponentiation(高精度小数乘法)
- POJ1001《Exponentiation》方法:模拟 高精度
- poj 1001 -- Exponentiation (大数计算,模拟)
- POJ1001 Exponentiation (解题报告)
- POJ 1001 Exponentiation
- POJ 1001 "Exponentiation"
- POJ 1001 Exponentiation
- [POJ][1001]Exponentiation
- Exponentiation - POJ 1001 高精度
- 【高精度】POJ1001-Exponentiation
- poj 1001 Exponentiation(高精度运算)
- Exponentiation(POJ-1001) Java大数例题
- POJ 1001 Exponentiation
- HDU 1063 Exponentiation&&POJ 1001 Exponentiation
- 【POJ 1001】Exponentiation 题解&代码(c++)
- POJ 1001 Exponentiation
- POJ-1001-Exponentiation
- 【POJ】1001 Exponentiation