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. 第六版 ...
随机推荐
- Spring Boot入门第一天:Hello, Spring Boot!
原文链接 1. 新建一个Maven Web项目. 2. 配置pom.xml文件. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...
- Windows Live Wirter
安装: 下载: Windows Live Writer (QQ 里) windows live writer 日志服务器发生问题 更新账户信息 从字面"editPost"我们不难看 ...
- GROUP by 方法 C#
1.用两层循环计算,前提条件是数据已经按分组的列排好序的. DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[] { ...
- Spring Boot 针对 Java 开发人员的安装指南
Spring Boot 可以使用经典的开发工具或者使用安装的命令行工具.不管使用何种方式,你都需要确定你的 Java 版本为 Java SDK v1.8 或者更高的版本.在你开始安装之前,你需要确定你 ...
- VS Code设置中文插件
Vscode是一款开源的跨平台编辑器.默认情况下,vscode使用的语言为英文(en) 1)打开vscode工具: 2)使用快捷键组合[Ctrl+Shift+p],在搜索框中输入“configure ...
- session一二事
Session即回话,指一种持续性的.双向的连接.Session和Cookie在本质上没有什么区别,都是针对HTTP协议的局限性而提出的一种保持客户端和服务器间保持会话连接状态的机制. Session ...
- addEventListener调用带参数函数
当传递参数值时,使用"匿名函数"调用带参数的函数: <body> <button id="btn">click me</butto ...
- getopt实现传参自动识别
test.py #!/usr/bin/env python # -*- coding: utf-8 -*- import getopt import sys #-h-f-v为了下面的识别 opts,a ...
- 【JS】【3】标签显示几秒后自动隐藏
$("#XXX").show().delay(2000).hide(0); 2000,0:可选,速度,(毫秒:"slow":"fast") ...
- Leetcode 1003. 检查替换后的词是否有效
1003. 检查替换后的词是否有效 显示英文描述 我的提交返回竞赛 用户通过次数245 用户尝试次数273 通过次数249 提交次数500 题目难度Medium 给定有效字符串 "ab ...