原题链接

题目大意:给一个16位的数字,表示一个浮点数,按照规则转换成科学计数法表示。

解法:注释比较清楚了,注意浮点运算的四舍五入问题。

参考代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<string.h>
using namespace std; int main(){
char in[16],out[16];
int i,j,n,exp,man,zero;
double num; cout<<"Program 6 by team X"<<endl; //废话不能少,否则WA
while(scanf("%s",in)!=EOF){
man=0;
exp=0;
zero=1;
if(in[0]=='1')out[0]='-';
else out[0]=' ';
for(i=1;i<8;i++){
exp=exp<<1; //注意,移位的时候后面不能再跟算式,否则出错
exp+=(in[i]-'0'); //处理的是字符,要用ASCii码比较
if(in[i]!='0')zero=0;
}
exp=exp-63;
for(i=8;i<16;i++){
man=man<<1;
man+=(in[i]-'0');
if(in[i]!='0')zero=0;
}
num=(1+double(man)/256)*pow(2.0,exp);
exp=0;
if(num>10-1e-6){
while(num>10-1e-6){
num/=10;
exp++;
}
}
else if(num<1.0+1e-6){
while(num<1.0+1e-6){
num*=10;
exp--;
}
}
if(zero)cout<<" 0.000000e+000";
else{
cout<<out[0];
printf("%.6fe",num);
if(exp>=0){
cout<<"+0";
if(exp<10)cout<<'0';
cout<<exp;
}
else{
cout<<"-0";
if(exp>-10)cout<<'0';
cout<<-exp;
}
}
cout<<endl;
}
cout<<"End of program 6 by team X";
return 0;
}

ZOJ 1125 Floating Point Numbers的更多相关文章

  1. comparison of floating point numbers with equality operator. possible loss of precision while rounding values

    double值由外部传入 private void Compare(double value) { string text; ) //小数位后保留2位 { //小数点后保留2位小数 text = st ...

  2. zoj 2001 Adding Reversed Numbers

    Adding Reversed Numbers Time Limit: 2 Seconds      Memory Limit: 65536 KB The Antique Comedians of M ...

  3. ZOJ 2405 Specialized Four-Digit Numbers

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1405 要求找出4位数所有10进制.12进制.16进制他们各位数字之和相等. # ...

  4. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  5. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  6. ZOJ 1860:Dog & Gopher

    Dog & Gopher Time Limit: 2 Seconds      Memory Limit: 65536 KB A large field has a dog and a gop ...

  7. Floating Point Math

    Floating Point Math Your language isn't broken, it's doing floating point math. Computers can only n ...

  8. Python基础(二)

    本章内容: Python 运算符(算术运算.比较运算.赋值运算.逻辑运算.成员运算) 基本数据类型(数字.布尔值.字符串.列表.元组.字典.set集合) for 循环 enumrate range和x ...

  9. TileJSON

    TileJSON TileJSON is an open standard for representing map metadata. License The text of this specif ...

随机推荐

  1. [开发笔记]-Visual Studio 2012中为创建的类添加注释的模板

    为类文件添加注释,可以让我们在写代码时能够方便的查看这个类文件是为了实现哪些功能而写的. 一:修改类文件模板 找到类模版的位置:C:\Program Files (x86)\Microsoft Vis ...

  2. HDU 1693 二进制表示的简单插头dp

    题目大意: 找到多条回路覆盖所有非障碍格子,问这样回路的种数 这里的插头与URAL1519 不一样的是 只要管它是否存在即可,只需要1个二进制位表示状态 #include <cstdio> ...

  3. ajax跨域相关

    ajax 技术使用xmlhttprequest组件附送请求时,发送请求的url和本网页的url地址必须在同一个域名下如果需要跨域,可以使用iframe或者<javascript src=&quo ...

  4. Android 查看webview里面的图片

    今天介绍一下怎么查看WebView里面的图片,首先要设置WebView能够支持JavaScript,然后实现JavaScript的监听接口: mWebView.getSettings().setJav ...

  5. self.view 的不当操作造成死循环

    如题,在创建ContentView的时候,例子如下 NSString *viewClassName = NSStringFromClass([self class]); viewClassName = ...

  6. 解密SQL SERVER 2005加密存储过程,函数

    在SQL SERVER 2005中必须用专用管理连接才可以查看过程过程中用到的表 EG:sqlcmd -A 1>use test 2>go 1>sp_decrypt 'p_testa ...

  7. matlab的正则表达式讲解[转]

    引言.啥是正则表达式?正则表达式是干啥的?我理解就和我们在word或者其他编辑软件里点的查找.替换的作用是差不多的,不过功能要强大的多,当然使用起来也稍微复杂一些.书上的定义差不多是这样的:正则表达式 ...

  8. python3爬虫再探之豆瓣影评数据抓取

    一个关于豆瓣影评的爬虫,涉及:模拟登陆,翻页抓取.直接上代码: import re import time import requests import xlsxwriter from bs4 imp ...

  9. 产生n位元的所有格雷码

    原文链接:http://blog.csdn.net/beiyeqingteng/article/details/7044471 问题:产生n位元的所有格雷码. 格雷码(Gray Code)是一个数列集 ...

  10. iOS开发:集成支付宝(遇见的坑和便捷撸代码)

    开发iOS最重要的就是支付了,天朝之内最常用的就是支付宝了,下面就以自己的经历说明如何集成支付宝+遇见的坑. 首先,集成支付宝最好别使用Cocoapods,很多人都说使用起来很方便,可是我每次只要使用 ...