POJ1001 解题报告
来源:互联网 发布:js显示当前时间 编辑:程序博客网 时间:2024/06/06 01:04
Description
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
Output
Sample Input
95.123 120.4321 205.1234 156.7592 998.999 101.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566
Accepted 140K47MS C++4022B 2015-02-06 22:23:01
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#define BASELEN 6
#define EXPLIMIT 25
#define RESULTLEN ((BASELEN - 1)*EXPLIMIT)
#define BITDIF (RESULTLEN-BASELEN)
int ftod(char *,int *);
void PreciseMultiply(int *,int,int*);
void Overflow(int *i_register, int k);
void dtof(int*,int,char*);
void FormatPrintPreciseValue(char*);
int main(void)
{
char c_base[BASELEN] = { 0 };
int exp = 0;
while (scanf("%s %d", c_base, &exp) == 2)
{
int i_base[BASELEN] = { 0 };
int DotPosition = 0;
int i_result[RESULTLEN] = { 0 };
char c_result[RESULTLEN] = { 0 };
DotPosition=ftod(c_base,i_base);
PreciseMultiply(i_base,exp,i_result);
DotPosition = DotPosition*exp;
dtof(i_result,DotPosition,c_result);
FormatPrintPreciseValue(c_result);
}
}
int ftod(char *c_base, int *i_base)
{
int DotPos = 0;
for (int i = 0; i < BASELEN; i++)
{
if (c_base[i]=='.')
{
DotPos =i;
}
i_base[i] = c_base[i] - '0';
}
for (int j = DotPos; j >0 ; j--)
{
i_base[j] = i_base[j - 1];
}
i_base[0] = 0;
DotPos = 5 - DotPos;
return DotPos;
}
void PreciseMultiply(int *i_base, int exp, int i_result[RESULTLEN])
{
for (int i = 0; i < BASELEN; i++)
{
i_result[i+BITDIF] = i_base[i];
}
while (exp>1)
{
int i_register[RESULTLEN] = { 0 };
for (int j = 1; j <= 6;j++)
{
for (int k = 1; k<RESULTLEN; k++)
{
int tmp = i_base[BASELEN-j] * i_result[RESULTLEN-k];
i_register[RESULTLEN-k-j+1] += tmp % 10;
i_register[RESULTLEN-k-j] += tmp / 10;
Overflow(i_register, k);
}
}
for (int l = 0; l < RESULTLEN; l++)
{
i_result[l] = i_register[l];
}
exp--;
}
}
void Overflow(int *i_register,int k)
{
for (int i = k; i >0; i--)
{
int tmp = i_register[i];
i_register[i] = tmp % 10;
i_register[i - 1] += tmp / 10;
}
}
void dtof(int *i_result, int DotPosition, char *c_result)
{
DotPosition = RESULTLEN - 1 - DotPosition;
for (int i = 0; i < DotPosition; i++)
{
i_result[i] = i_result[i + 1];
}
for (int i = 0; i < RESULTLEN; i++)
{
c_result[i] = i_result[i]+'0';
}
c_result[DotPosition] = '.';
}
void FormatPrintPreciseValue(char *c_result)
{
int headzeromark = 0;
int trailingzeromark = RESULTLEN-1;
for (int i = 0; i < RESULTLEN; i++)
{
if (c_result[i]=='0'&&c_result[i+1]=='0')
{
headzeromark ++;
}
else
{
headzeromark++;
// if (c_result[i+1] == '.')
{
// headzeromark--;
}
break;
}
}
for (int j = RESULTLEN-1; j > 0; j--)
{
if (c_result[j]=='0'&&c_result[j-1]=='0')
{
trailingzeromark--;
}
else
{
if (c_result[j]=='0')
{
trailingzeromark--;
}
if (c_result[j-1]=='.')
{
trailingzeromark--;
}
break;
}
}
for (int k = headzeromark; k<=trailingzeromark ; k++)
{
printf("%c", c_result[k]);
}
printf("\n");
}
- POJ1001解题报告
- poj1001解题报告
- POJ1001 Exponentiation (解题报告)
- poj1001 Exponentiation 解题报告
- POJ1001解题报告
- POJ1001 解题报告
- poj1001解题报告+测试数据
- poj1001 解题报告
- poj1001解题报告
- poj1001:1001:Exponentiation解题报告
- poj1001解题报告(高精度浮点数乘法)
- POJ1001 求高精度幂 ACM解题报告(高精度模板)
- POJ1001
- poj1001
- poj1001
- POJ1001
- POJ1001
- poj1001
- osg学习第一篇:矩阵
- iOS 开发之常用框架
- STL algorithm accumulate vector<string> demo
- 我的2015计划,目标
- 修改样式表时在某些浏览器(如360)下遇到Cannot read property 'style' of undefined错误的解决方案
- POJ1001 解题报告
- 流媒体服务器实现
- ORACLE数据库—参数文件
- spring 配置hibernate事务处理
- 【Servlet笔记】servlet 代码生成验证码
- linux .o a .so .la .lo的区别
- 欢迎使用CSDN-markdown编辑器
- HDOJ 胜利大逃亡 1253
- OGEngine使用