http://poj.org/problem?id=1001

这是一道高精度的运算,如果你之前有写过那种高精度的乘法的题目的话,做这个也还是比较简单的。、

思路:我是首先把小数点的位置确定下来,然后其他的数字不分一起运算,最后在添加小数点。

 #include <stdio.h>
#include <iostream>
#include <string.h> int nu[],num[];
char inp[];
int n,loc; int nc() //这一个就是高精度的乘法的算法用的。
{
int tmp[]={};
for(int i=;i<;i++)
for(int m=;m<=;m++)
{
tmp[m+i]+=nu[i]*num[m];
}
for(int i=;i<;i++)
{
if(tmp[i]>=){
tmp[i+]+=tmp[i]/;
tmp[i+]+=(tmp[i]-(tmp[i]/)*)/;
tmp[i]=tmp[i]%;
}
else if(tmp[i]>=){
tmp[i+]+=tmp[i]/;
tmp[i]=tmp[i]%;
}
nu[i]=tmp[i];
}
return ;
} int main()
{
// freopen("in.txt","r",stdin);
while(scanf("%s%d",inp,&n)!=EOF)
{
memset(nu,,sizeof(nu));
int i,m;
for(i=;inp[i]!='.';i++); //找出小数点的位置。
loc=(-i)*n;
for(i=,m=;i>=;i--,m++)
{
if(inp[i]=='.') m--;
else {
num[m]=inp[i]-'';
nu[m]=inp[i]-'';
}
}
for(i=;i<n;i++)
nc();
int mark=,flog=;
for(int i=;i<=;i++) //用来除去后导0的。
{
if(i==loc){
mark=i;
flog=;
break;
}if(nu[i]!=){
mark=i;
break;
}
}
// printf("%d\n",mark);
for(i=,m=;i>=mark;i--,m--)
{
if(nu[i]!=&&i==m) m--;
if(i!=m) printf("%d",nu[i]);
if(i==loc||(loc>i&&i==m))
{
if(!flog) printf(".");
m--;
}
}
printf("\n");
}
return ;
}

poj 1001的更多相关文章

  1. POJ 1001 Exponentiation(大数运算)

    POJ 1001 Exponentiation 时限:500 ms   内存限制:10000 K 提交材料共计: 179923   接受: 43369 描述:求得数R( 0.0 < R < ...

  2. [POJ 1001] Exponentiation C++解题报告 JAVA解题报告

        Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 126980   Accepted: 30 ...

  3. Poj 1001 / OpenJudge 2951 Exponentiation

    1.链接地址: http://poj.org/problem?id=1001 http://bailian.openjudge.cn/practice/2951 2.题目: Exponentiatio ...

  4. POJ 1001 解题报告 高精度大整数乘法模版

    题目是POJ1001 Exponentiation  虽然是小数的幂 最终还是转化为大整数的乘法 这道题要考虑的边界情况比较多 做这道题的时候,我分析了 网上的两个解题报告,发现都有错误,说明OJ对于 ...

  5. POJ 1001 Exponentiation 无限大数的指数乘法 题解

    POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...

  6. POJ 1001 Exponentiation(JAVA,BigDecimal->String)

    题目 计算实数a的n次方,具体输出格式看案例 import java.util.*; import java.math.*; public class Main { public static voi ...

  7. [POJ] #1001# Exponentiation : 大数乘法

    一. 题目 Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 156373   Accepted: ...

  8. POJ 1001 Exponentiation

    题意:求c的n次幂……要求保留所有小数…… 解法:一开始只知道有BigInteger……java大数+模拟.第一次写java大数……各种报错各种exception……ORZ 没有前导0和小数后面的补位 ...

  9. POJ 1001 Exponentiation 模拟小数幂

    模拟小数幂 小数点位 pos 非零末位 e 长度 len 只有三种情况 pos > len pos < e e < pos < len #include <iostrea ...

随机推荐

  1. fatal: Paths with -a does not make sense.

    git commit -am '*屏蔽设置缓存' htdocs/s.php fatal: Paths with -a does not make sense. 应该用下面的这样. git commit ...

  2. centos 安装 mysql5.6

    转载自 http://www.cnblogs.com/littlehb/archive/2013/04/02/2995007.html Mysql 5.5以后使用了CMake进行安装,参考与以前的区别 ...

  3. BufferedReader readLine()方法

    控制台输入字符串之后回车,后台接收传来的字符串,代码如下: import java.io.BufferedReader; import java.io.IOException; import java ...

  4. 江湖救急:webbrowser中js文件丢失问题~

    页面中,有一个按钮,点击按钮通过js create 了一个 script标签 ,链接加载一个外部js文件,执行该js文件 $("#a").click(function(){ $.g ...

  5. 免费的ER 设计软件调研

    目标: 找到一个免费的ER 设计软件, 适合数据仓库项目开发. 结果: 经初步调研, Oracle的 SQL Developer Data Modeler基本满足需求. 但在功能和操作性等方面, 较P ...

  6. [译]git reflog

    用法 git reflog 显示整个本地仓储的commit, 包括所有branch的commit, 甚至包括已经撤销的commit, 只要HEAD发生了变化, 就会在reflog里面看得到. git ...

  7. Linq→join中指定多个条件

    还是习惯先撸一段SQL * FROM User_Pic P AND P.Guid = R.UserPicGuid ORDER BY PicSize DESC 然后发现Linq中的join不能多条件.. ...

  8. 关于EXCEL学习的那些事

    由于在客服中心工作,虽然日常工作基本与数据打交道,但是周围的同事对EXCEL基本不怎么了解,仅会一些基本操作.所以基本日常我会被问到许多EXCEL相关的问题,也针对这个做了一些整理与思考. 之后无意看 ...

  9. 使用ajax获取JSON数据的jQuery代码的格式

    具体的也可以参考:http://www.w3cfuns.com/notes/16039/2b004b1bcdf79092f2e66b2bbe9f51df.html

  10. cf#305 Mike and Foam(容斥)

    C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...