Cracking The Coding Interview5.2
//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的更多相关文章
- 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 ...
- Cracking the coding interview
写在开头 最近忙于论文的开题等工作,还有阿里的实习笔试,被虐的还行,说还行是因为自己的水平或者说是自己准备的还没有达到他们所需要人才的水平,所以就想找一本面试的书<Cracking the co ...
- Cracking the coding interview 第一章问题及解答
Cracking the coding interview 第一章问题及解答 不管是不是要挪地方,面试题具有很好的联系代码总用,参加新工作的半年里,做的大多是探索性的工作,反而代码写得少了,不高兴,最 ...
- Cracking the coding interview--问题与解答
http://www.hawstein.com/posts/ctci-solutions-contents.html 作者:Hawstein出处:http://hawstein.com/posts/c ...
- 《cracking the coding intreview》——链表
前言 最近准备暑假回家回家修整一下,所以时间大部分用来完成项目上的工作,同时为了9月份的校招,晚上的时间我还在学习<cracking the coding intreview>,第二章链表 ...
- Cracking the Coding Interview(Trees and Graphs)
Cracking the Coding Interview(Trees and Graphs) 树和图的训练平时相对很少,还是要加强训练一些树和图的基础算法.自己对树节点的设计应该不是很合理,多多少少 ...
- 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 ...
- 《Cracking the Coding Interview》读书笔记
<Cracking the Coding Interview>是适合硅谷技术面试的一本面试指南,因为题目分类清晰,风格比较靠谱,所以广受推崇. 以下是我的读书笔记,基本都是每章的课后习题解 ...
- Cracking the coding interview目录及资料收集
前言 <Cracking the coding interview>是一本被许多人极力推荐的程序员面试书籍, 详情可见:http://www.careercup.com/book. 第六版 ...
随机推荐
- java.lang.RuntimeException: Unable to start activity ComponentInfo……AppCompat does not support the current theme features
Android测试时出现闪退的问题,出现了如下所示异常: java.lang.RuntimeException: Unable to start activity ComponentInfo{thon ...
- 手动脱UPX压缩壳
示例程序演示 样例程序选择win7自带的notepad.exe,该程序原本是没有加壳的: 拷贝notepad.exe文件一个副本,重命名为notepad - upx.exe,我们对notepad - ...
- LeetCode--682--棒球比赛(java)
你现在是棒球比赛记录员. 给定一个字符串列表,每个字符串可以是以下四种类型之一:1.整数(一轮的得分):直接表示您在本轮中获得的积分数.2. "+"(一轮的得分):表示本轮获得的得 ...
- git回退代码到某次commit
回退命令: $ git reset --hard HEAD^ 回退到上个版本 $ git reset --hard HEAD~3 回退到前3次提交之前,以此类推,回退到n次提交之前 $ git res ...
- python-django rest framework框架之dispatch方法源码分析
1.Django的 CBV 中在请求到来之后,都要执行dispatch方法,dispatch方法根据请求方式不同触发 get/post/put等方法 class APIView(View): def ...
- poj 1080 基因组(LCS)
Human Gene Functions Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19376 Accepted: ...
- 迭代器与泛型for
迭代器与closure function allwords() local line=io.read() return function() while line do local s,e=strin ...
- css层叠性冲突中的优先级
一.首先从CSS级别来进行优先级划分: CSS控制页面样式的四种方法: 1.行内样式 通过style特性 <p style=”color:#F00; background:#CCC; font- ...
- IQueryable 与 IEnumberable 接口的区别
IQueryable 与 IEnumberable 接口的区别是: IEnumberable<T> 泛型类在调用自己的 SKip 和 Take 等扩展方法之前数据就已经加载在本地内存里了, ...
- InnoDB存储引擎介绍-(6) 一. Innodb Antelope 和Barracuda区别
分类 Antelope是innodb-base的文件格式,Barracude是innodb-plugin后引入的文件格式,同时Barracude也支持Antelope文件格式.两者区别在于: 文件格式 ...