//Given a (decimal - e.g. 3.72) number that is passed in as a string, print the binary representation.If the number can not be represented accurately in binary, print “ERROR”.
//前面有个打印整数的了,这里只打印小数.
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
using namespace std; void print(int p)
{
vector<int> v;
for (int k = 0;k<32; k++)
{
int t = p&1;
v.push_back(t);
p=p>>1;
}
for (int i = v.size()-1;i>-1; i--)
{
cout<<v[i]<<" ";
}
cout<<endl;
} void mprintf(float f)
{
vector <int>v;
for (int k = 0; k<32; k++)
{
f = f *2;
if (f>=1)
{
f = f-1.0;
v.push_back(1);
}
else v.push_back(0);
cout<<v[k]<<" ";
} }
int main()
{
string str = "0.8";
float f = atof(str.c_str());
mprintf(f);
return 0;
}

Cracking The Coding Interview5.2的更多相关文章

  1. Cracking The Coding Interview5.1

    //You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set a ...

  2. Cracking the coding interview

    写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...

  3. Cracking the coding interview 第一章问题及解答

    Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...

  4. Cracking the coding interview--问题与解答

    http://www.hawstein.com/posts/ctci-solutions-contents.html 作者:Hawstein出处:http://hawstein.com/posts/c ...

  5. 《cracking the coding intreview》——链表

    前言 最近准备暑假回家回家修整一下,所以时间大部分用来完成项目上的工作,同时为了9月份的校招,晚上的时间我还在学习<cracking the coding intreview>,第二章链表 ...

  6. Cracking the Coding Interview(Trees and Graphs)

    Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...

  7. Cracking the Coding Interview(Stacks and Queues)

    Cracking the Coding Interview(Stacks and Queues) 1.Describe how you could use a single array to impl ...

  8. 《Cracking the Coding Interview》读书笔记

    <Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...

  9. Cracking the coding interview目录及资料收集

    前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...

随机推荐

  1. 把 java web application deploy 到 root

    http://stackoverflow.com/questions/5328518/deploying-my-application-at-the-root-in-tomcat You have a ...

  2. ubuntu 下Visual Studio Code 安装

    Build in Visual Studio Code Install VSCode The easiest way to install for Debian/Ubuntu based distri ...

  3. 雷林鹏分享:C# 环境

    C# 环境 在这一章中,我们将讨论创建 C# 编程所需的工具.我们已经提到 C# 是 .Net 框架的一部分,且用于编写 .Net 应用程序.因此,在讨论运行 C# 程序的可用工具之前,让我们先了解一 ...

  4. English trip V1 - B 5.Is It Cold Outside? 外面很冷? Teacher:Corrine Key: weather

    In this lesson you will learn to talk about the weather. 本节课将学习到关于天气 课上内容(Lesson) 词汇(Key Word ) # 关于 ...

  5. MyEclipse下自定义(支持html5的)JSP模板--JSP

    需求:由于某些Mclipse版本发行的比较早,所以在有些版本(比如Mclipse2014,至于其他版本博主不知能不能创建html5格式的JSP页面)里创建JSP页面时html部分不是html5格式的. ...

  6. Spring Boot 针对 Java 开发人员的安装指南

    Spring Boot 可以使用经典的开发工具或者使用安装的命令行工具.不管使用何种方式,你都需要确定你的 Java 版本为 Java SDK v1.8 或者更高的版本.在你开始安装之前,你需要确定你 ...

  7. GPLT L2-014 列车调度

    题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805063166312448 分析:明显从右到左列车的序号需要依 ...

  8. Excel文件的读写

    import xlsxwriter,xlrd import sys,os.path fname = 'zm6.xlsx' if not os.path.isfile(fname): print ('文 ...

  9. hbase知识

    HBASE是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统 HBASE的目标是存储并处理大型的数据,更具体来说是仅需使用普通的硬件配置,就能够处理由成千上万的行和列所组成的大型数据. HBASE ...

  10. ABAP游标

    DATA: BEGIN OF count_line, carrid TYPE spfli-carrid, count TYPE i, END OF count_line, spfli_tab TYPE ...