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 ...
随机推荐
- vba实现excel多表合并
Excel多表合并之vba实现 需求 保留列名,复制每一个excel里的数据,合并到一个excel 操作步骤 将要合并的文件放在同一文件夹下,复制过来就好(ps:最好不要直接操作原数据文件,避免操作失 ...
- C#中base的作用
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- Task 回调
前正无生意,且记录Task回调之用法. using System; using System.Collections.Generic; using System.Diagnostics; using ...
- C# 调接口
上一个项目,需要mvc管理后台调接口项目,以便后期的重构扩展,调研后发现后台用的ajax请求,直接调接口可能会有跨域问题,最终在c#代码中实现了这个需求. 1,Ajax请求后台 将接口所需参数传入 2 ...
- Centos7.5的定制化安装
一.前言 关于定制化centos7.5的镜像真的是历经波折,前前后后.来来回回尝试了不少于20次,上网找了各种关于定制7系统的方法,都没有成功... 但最终功夫不负有心人终于解决了,O(∩_∩)O哈哈 ...
- java web高级编程 笔记1
chapter1:了解web应用程序 web应用程序主要组件: Servlet 过滤器 监听器 JSP chapter2:各类web容器介绍 略 chapter3:Servlet介绍 Servlet是 ...
- 洛谷P4495 [HAOI2018]奇怪的背包(数论)
题面 传送门 题解 好神仙的思路啊--orzyyb 因为不限次数,所以一个体积为\(V_i\)的物品可以表示出所有重量为\(\gcd(V_i,P)\)的倍数的物品,而所有物品的总和就是这些所有的\(\ ...
- 洛谷P4015 运输问题(费用流)
传送门 源点向仓库连费用$0$,流量为储量的边,商店向汇点连费用$0$,流量为需求的边,然后仓库向商店连流量$inf$,费用对应的边,跑个费用流即可 //minamoto #include<io ...
- js事件处理程序return false ,preventDefault,returnValue
面试题目中,经常会被问到如何阻止默认行为. 以下是<javascript权威指南>书中的内容,详情可以去看书. 能够取消事件默认操作的方法有三种 1.属性注册的事件处理程序的返回值fals ...
- Hibernate学习笔记(二)—— 实体规则&对象的状态&一级缓存
一.持久化类 1.1 什么是持久化类? Hibernate是持久层的ORM映射框架,专注于数据的持久化工作.所谓的持久化,就是将内存中的数据永久存储到关系型数据库中.那么知道了什么是持久化,什么又是持 ...