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 ...
随机推荐
- python 读取mysql存储的文件路径下载文件,内容解析,上传七牛云,内容入es
#!/usr/bin/env python # -*- coding: utf-8 -*- import ConfigParser import json import os import re fr ...
- AD对象DirectoryEntry本地开发
DirectoryEntry类如果需要在本地计算机开发需要满足以下条件: 1.本地计算机dns解析必须和AD域控制器的dns保持一致,如图: 2.必须模拟身份验证,才能操作查询AD用户 /// < ...
- Transaction And Lock--快照事务隔离级别
--================================================--准备数据GOCREATE DATABASE DB5GOUSE DB5GOCREATE TABLE ...
- SQL server T-sql语句查询执行顺序
前言 数据库的查询执行,毋庸置疑是程序员必备的技能之一,然而数据库查询执行的过程绚烂多彩,却是很少被人了解,今天我们来深入了解下sql查询的来龙去脉,为查询的性能优化打个基础 这篇博客,摒弃查询优化性 ...
- angular 服务之间依赖注入
import { Injectable } from '@angular/core'; @Injectable() export class LoggerServiceService { constr ...
- 如何使用 channel
如何使用 Channel 例子来自于Concurrency is not parallelism Google Search: A fake framework v1.0 var ( Web = fa ...
- 协程《二》greenlet模块
一 greenlet模块 如果我们在单个线程内有20个任务,要想实现在多个任务之间切换,使用yield生成器的方式过于麻烦(需要先得到初始化一次的生成器,然后再调用send...非常麻烦),而使用gr ...
- ARKit的使用
//创建场景 let scene = SCNScene() /* //1.几何 let box = SCNBox.init(width: 0.1, height: 0.1, length: 0.1, ...
- springboot整合mybatis,druid,mybatis-generator插件完整版
一 springboot介绍 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...
- PHP编程入门与应用
基础语法.流程控制语句.数组的应用.字符串的应用————3天 PHP函数————3天 面向对象————3天 文件处理————2天 获取页面数据.会话处理————3天 数据库————5天 XML和JSO ...