TOJ 2861 Octal Fractions
描述
Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.75 in octal is 0.953125 (7/8 + 5/64) in decimal. All octal numbers of n digits to the right of the octal point can be expressed in no more than 3n decimal digits to the right of the decimal point.
Write a program to convert octal numerals between 0 and 1, inclusive, into equivalent decimal numerals.
输入
The
input to your program will consist of octal numbers, one per line, to
be converted. Each input number has the form 0.d1d2d3 ... dk, where the
di are octal digits (0..7). There is no limit on k.
输出
Your output will consist of a sequence of lines of the form
0.d1d2d3 ... dk [8] = 0.D1D2D3 ... Dm [10]
where
the left side is the input (in octal), and the right hand side the
decimal (base 10) equivalent. There must be no trailing zeros, i.e. Dm
is not equal to 0.
样例输入
0.75
0.0001
0.01234567
样例输出
0.75 [8] = 0.953125 [10]
0.0001 [8] = 0.000244140625 [10]
0.01234567 [8] = 0.020408093929290771484375 [10]
题目来源
题目意思就是把小数位的八进制转换为十进制。
【转换方法】
例如:0.01234567
则是0/(8)+1/(8*8)+2/(8*8*8)+3/(8*8*8*8)+...+7/(8*8*8*8*8*8*8*8)=0.020408093929290771484375
因为要转换的数字挺大的所以要用数组来存放小数位,另外计算的公式也转换为:((((7/8+6)/8+5)/8+4)/8+...+0)/8
#include <stdio.h>
#include <string.h>
#define MAXN 10000
char d[MAXN];
int D[MAXN];
int main()
{
int cnt;//表示当前数组存放的位置
int next;
int current;
while(gets(d)!=NULL){
int len=strlen(d);
int Dlen=;
memset(D,,sizeof(D));
for(int i=len-; i>=; i--){
cnt=;
int num=d[i]-'';
next=num;
while(next!= || cnt<Dlen){
current=next*+D[cnt];
D[cnt++]=current/;
next=current%;
}
Dlen=cnt;
}
printf("%s [8] = 0.",d);
for(int i=; i<cnt; i++){
printf("%d",D[i]);
}
printf(" [10]\n");
}
return ;
}
TOJ 2861 Octal Fractions的更多相关文章
- Octal Fractions
Octal Fractions Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 149 Solved: 98 Description Fractions ...
- Octal Fractions java秒 C++
Octal Fractions 题目抽象: 将八进制小数转换成十进制小树.小数的为数很大. 可以用java 中的BigDeciaml 秒掉. time:297ms 1 import java. ...
- hdu 1376 Octal Fractions
刚开始做这题时,用的是0.75[8]=(7/8+5/64)[10]这个,但是总是WA…………无语了…… 后来看别人的解题报告,知道了另外一个就是0.75[8]=((5/8+7)/8)[10],从低位向 ...
- POJ Octal Fractions(JAVA水过)
题目链接:id=1131" target="_blank">CLICK HERE~ 尽管java一下模拟水过,可是我看到别人的一段奇妙代码,贴出和大家共享. imp ...
- poj 1131 Octal Fractions(高精度小数进制转换) Java
虽然题目那么长其实就是把8进制的浮点数转换成10进制,为了练习Java Biginteger 类 我这里用的是Java,也可以用数组模拟. import java.math.BigDecimal; i ...
- Poj1131-Octal Fractions
Octal Fractions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6669 Accepted: 3641 D ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- HOJ题目分类
各种杂题,水题,模拟,包括简单数论. 1001 A+B 1002 A+B+C 1009 Fat Cat 1010 The Angle 1011 Unix ls 1012 Decoding Task 1 ...
- [Hanani]JAVA大数相关学习记录
1.Basic remains 题目链接 涉及内容: |大数读入|大数模|大数进制读入时转化为十进制|大数输出时转化为其他进制输出| import java.io.*; import java.mat ...
随机推荐
- MultiDataTrigger
MultiDataTrigger是多条件数据触发器 和MltiTrigger是同样的,只不过前者是数据,后者是属性. 这个是基本的使用语法 <MultiDataTrigger> <M ...
- Mybatis中的连接池
Mybatis中DataSource的存取 MyBatis是通过工厂模式来创建数据源DataSource对象的,MyBatis定义了抽象的工厂接口:org.apache.ibatis.datasour ...
- zookeeper安装和使用 windows
的 Zookeeper 是以 3.4.5 这个稳定版本为基础,最新的版本可以通过官网 http://hadoop.apache.org/zookeeper/来获取,Zookeeper 的安装非常简单, ...
- kali linux之被动信息收集(dns信息收集,区域传输,字典爆破)
公开可获取的信息,不与目标系统产生交互,避免留下痕迹 下图来自美军方 pdf链接:http://www.fas.org/irp/doddir/army/atp2-22-9.pdf 信息收集内容(可利用 ...
- IO相关3(string流)
sstream 头文件定义了三个类型来支持内存 IO,这些类型可以向 string 写入数据,从 string 读取数据,就像 string 是一个 IO 流一样. istringstream 从 s ...
- numpy.histogram 官方手册
numpy.histogram numpy.histogram(a, bins=10, range=None, normed=False, weights=None, density=None) Co ...
- form表单提交回调函数
form表单没有回调函数,不过可以通过jquery-form.js这个插件来实现回调函数: <form id="addform" class="form-horiz ...
- Django template的html明明改了,前端页面居然没有对应变化?!---Django的小坑
写django的时候,我有个模板的名字叫detail.html,被detail视图函数渲染 因为那个detail写乱了,但是里面有东西要参考,我没删掉它,改名为detail_old.html,又在目录 ...
- ThinkCMF if 标签
用法示例: <if condition="($name eq 1) OR ($name gt 100) "> value1 <elseif condition=& ...
- JsonToHtml
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...