poj-1131-(大数)八进制转化成十进制

简介: Description Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.

Description

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.

Input

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.

Output

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.

Sample Input

0.75
0.0001
0.01234567

Sample Output

0.75 [8] = 0.953125 [10]
0.0001 [8] = 0.000244140625 [10]
0.01234567 [8] = 0.020408093929290771484375 [10]
import java.util.*;   //包含集合框架、遗留的 collection 类、事件模型、日期和时间设施、
               //  国际化和各种实用工具类(字符串标记生成器、随机数生成器和位数组
                //日期Date类、堆栈Stack类、向量Vector类等 import java.math.*; //包含大数的类型 import java.io.*;       //包括:文件读写、标准设备输出等。Java中IO是以流为基础进行输入输出的,所有数据被串行化写入输出流,或者从输入流读入。 public class Main{ public static void main(String[] args){ Scanner cin= new Scanner(System.in); BigDecimal a=BigDecimal.valueOf(1),eight=BigDecimal.valueOf(8);; //定义大数类型并且赋初值 String str; while(cin.hasNext()) { BigDecimal an=BigDecimal.valueOf(0); BigDecimal b=a.divide(eight); //对大数的操作不能用简单的基本运算符,必须用函数操作
                        //add();subtract();multiply();divide();                         //加减乘除计算函数 str=cin.nextLine();            //大数是已字符串形式输入输出 for(int i=2;i<str.length();i++) { an=an.add(b.multiply(new BigDecimal(str.charAt(i)-48))); //str.charAt(i)————位置上的字符; b=b.divide(eight); } System.out.println(str+" [8]"+" = "+an.toString()+" [10]"); } }}

  

相关文章
|
存储 C语言
中缀表达式转后缀表达式
本文提供了一个C语言程序,用于将中缀表达式转换为后缀表达式,并计算后缀表达式的结果,包括处理运算符优先级、括号匹配以及基本的四则运算。
359 0
|
9月前
|
Web App开发 监控 前端开发
React音频播放控制组件开发深度解析
本文介绍了构建React音频控制组件时遇到的关键问题及优化方案。主要包括: 1. **状态同步难题**:解决播放按钮与音频状态不同步的问题,通过双向绑定机制确保一致。 2. **跨浏览器兼容性**:处理Safari和Chrome预加载策略差异,确保`duration`属性正确获取。 3. **进度控制优化**:避免使用`setInterval`,采用`requestAnimationFrame`提升性能;优化拖拽交互,防止音频卡顿。 4. **音量控制进阶**:实现渐变音量调节和静音状态同步。
332 15
|
数据采集 数据可视化 数据挖掘
MATLAB进行文件读取
【10月更文挑战第7天】本文介绍了如何使用MATLAB进行文件读取和数据处理,涵盖读取文本、CSV和Excel文件,数据清洗、分析及可视化方法。通过具体代码示例,展示了从数据读取到处理的完整流程,包括数据归一化、特征选择和时间序列数据处理等进阶技术。结合实际案例,帮助读者掌握MATLAB在数据分析中的应用。
|
存储 监控 数据挖掘
ERP系统中的客户满意度调查与反馈处理解析
【7月更文挑战第25天】 ERP系统中的客户满意度调查与反馈处理解析
1120 0
|
机器学习/深度学习 并行计算 PyTorch
PyTorch与CUDA:加速深度学习训练
【4月更文挑战第18天】本文介绍了如何使用PyTorch与CUDA加速深度学习训练。CUDA是NVIDIA的并行计算平台,常用于加速深度学习中的矩阵运算。PyTorch与CUDA集成,允许开发者将模型和数据迁移到GPU,利用`.to(device)`方法加速计算。通过批处理、并行化策略及优化技巧,如混合精度训练,可进一步提升训练效率。监控GPU内存和使用调试工具确保训练稳定性。PyTorch与CUDA的结合对深度学习训练的加速作用显著。
|
数据建模 Go vr&ar
idea配置go依赖下载
idea配置go依赖下载
504 0
|
机器学习/深度学习 人工智能 监控
【AI 现况分析】AI 算法偏见和歧视分析
【1月更文挑战第27天】【AI 现况分析】AI 算法偏见和歧视分析
|
XML 数据管理 编译器
Qt+GDAL开发笔记(二):在windows系统msvc207x64编译GDAL库、搭建开发环境和基础Demo
上一篇使用mingw32版本的gdal,过程曲折,为更好的更方便搭建环境,在windows上msvc方式对于库比较友好。
|
安全 Ubuntu
metasploitable2安装实战
metasploitable2安装实战
1044 0