09 2015 档案
摘要:9.10 You have a stack of n boxes, with widths w., heights hir and depths drThe boxes cannot be rotated and can only be stacked on top of one another i...
阅读全文
摘要:在C++编程中,有时候要求我们把数据保留小数点后几位,或是保留多少位有效数字等等,那么就要用到setiosflags和setprecision函数,记得要包含头文件#include ,请参考下面的示例:#include #include // Need this using namespac...
阅读全文
摘要:9.9 Write an algorithm to print all ways of arranging eight queens on an 8x8 chess board so that none of them share the same row, column or diagonal. ...
阅读全文
摘要:Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nu
阅读全文
摘要:C++的STL中提供了很强大的排序函数sort,可以对任意数组,结构体及类进行排序,下面我们先来看最简单的数组排序。默认的升序排列,我们也可以在后面加上less或greater来告诉编译器我们想要的排序顺序。 vector<int> v = {2, 0, 1, 5, 9, 2, 7}; // Asc
阅读全文
摘要:DescriptionIn the city, there is a one-way straight highway starts from the northern end, traverses the whole city southward, and finishes at the sout...
阅读全文
摘要:9.8 Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents) and pennies (1 cent), write code to calculate the number of w...
阅读全文
摘要:Cosine similarity is a measure of similarity between two vectors of an inner product space that measures the cosine of the angle between them. The cos...
阅读全文
摘要:在写paper的时候,我们常常要给公式编号,难道我们要在公式和最右边的序号之间疯狂按空格键吗,当然不是,我们可以有更高效的方法来完成。首先我们插入一个1x3的表格,然后调节首尾两个格子的大小,借助标尺(可以在视图栏View中开启)将其调小到合适位置然后我们在尾部的格子中先填入括号(),然后指针放到中...
阅读全文
摘要:9.7 Implement the "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional a...
阅读全文
摘要:Template:1.A. Author Surname, 'Title', Year Published, (accessed 10 October 2013).Example:1.I. Heap, 'the Gloves', Imogenheap.co.uk, 2012, (access...
阅读全文
摘要:9.6 Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n-pairs of parentheses.EXAMPLEInput: 3Output: ((())),...
阅读全文
摘要:Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation -- it e
阅读全文
摘要:9.5 Write a method to compute all permutations of a string.LeetCode上的原题,请参加我之前的博客Permutations 全排列和Permutations II 全排列之二。解法一:class Solution {public: ...
阅读全文
摘要:Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, giv
阅读全文
摘要:9.4 Write a method to return all subsets of a set.LeetCode上的原题,请参见我之前的博客Subsets 子集合和Subsets II 子集合之二。解法一:class Solution {public: vector > getSubset...
阅读全文
摘要:9.3 A magic index in an array A[0.. .n-1] is defined to be an index such that A[i] = i. Given a sorted array of distinct integers, write a method to f...
阅读全文
摘要:9.2 Imagine a robot sitting on the upper left corner of an X by Y grid. The robot can only move in two directions: right and down. How many possible p...
阅读全文
摘要:9.1 A child is running up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many pos...
阅读全文
摘要:Given a string that contains only digits 0-9 and a target value, return all possibilities to add binaryoperators (not unary) +, -, or * between the di
阅读全文
摘要:在C++和Java的泛式编程中,模板template的使用是必不可少的,但是Java中没有template关键字,所以两者的写法还是有些许区别的,请参见如下代码:Java的模板// Javapublic class Cell { private K _key; private V _va...
阅读全文
摘要:8.10 Design and implement a hash table which uses chaining (linked lists) to handle collisions.这道题让我们实现一个简单的哈希表,我们采用了最简单的那种取余映射的方式来实现,我们使用Cell来保存一对对的k...
阅读全文
摘要:在Java中,如果A是基类,B是A的派生类,那么instanceof可以用来判断一个实例对象是A还是B,相当于一个二元操作符,但与==, >, (a)) { // Process B } if (C *c = dynamic_cast (a)) { // P...
阅读全文
摘要:快捷键 功能解释 工具操作 enter 完成当前操作 ~ 终止当前操作 insert 插入工具编辑模式 w 移动工具 e 旋转工具 r 缩放工具 y 非固定排布工具 shift+Q 选择工具,(切换到)成分图标菜单 alt+Q 选择工具,(切换到)多边形选择图标菜单 Q 选择工具,(切换到)成分图标...
阅读全文
摘要:8.9 Explain the data structures and algorithms that you would use to design an in-memory file system. Illustrate with an example in code where possibl...
阅读全文
摘要:8.8 Othello is played as follows: Each Othello piece is white on one side and black on the other. When a piece is surrounded by its opponents on both ...
阅读全文
摘要:8.7 Explain how you would design a chat server. In particular, provide details about the various backend components, classes, and methods. What would ...
阅读全文
摘要:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. Example 1: Input: n = 12 O
阅读全文
摘要:之前在机子装了个很早版本的MinGW,苦于不支持c++11,所以打算卸载掉安装个新版本的。可是网上找了很多版本装好后,编译成功,运行的时候总是弹出 *.exe has stopped working的错误,试了好几个都不行,很苦恼,最后终于找到了一个64位的MinGW,我装的是4.8.1版本的,亲测...
阅读全文
摘要:8.6 Implement a jigsaw puzzle. Design the data structures and explain an algorithm to solve the puzzle. You can assume that you have a f itsWith metho...
阅读全文
摘要:8.5 Design the data structures for an online book reader system.这道题OOB的题让我们设计一个在线读书系统,还是没有任何提示,所以发挥空间很大。根据书上的解答,我们设计一个具有基本功能的系统:1. 用户会员的建立和延长2. 搜索书库中的...
阅读全文
摘要:vtkMatrix4x4是VTK中的一个表示4x4矩阵的一种数据结构,有时候我们想把其保存到一个文件中,那么可以使用如下的代码:void writeVtkMatrix4x4ToFile(const vtkMatrix4x4 *m, char *filename) { ofstream fout...
阅读全文
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line.ExampleGiven 4 points:(1,2),(3,6),(0,0),(1,3).The max...
阅读全文
摘要:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c
阅读全文
摘要:8.4 Design a parking lot using object-oriented principles. LintCode上的原题,请参见我的另一篇博客Parking Lot 停车场问题。 这道题让我们实现一个停车位的数据结构,由于题目没给任何多余的信息,所以自由度很大,比如能停放什么种
阅读全文
摘要:在C++的OOB编程中,有时候我们会遇到这样的错误Error: 'has incomplete type',forward declaration of 'class x',那么是什么原因引起的这个问题呢,我们首先来看下面这段代码:// Error: field '_a' has incomplet...
阅读全文
摘要:8.3 Design a musical jukebox using object-oriented principles.CareerCup这书实在是太不负责任了,就写了个半调子的程序,说是完整版也可以下载到,但是我怎么找不到,谁知道在哪里下载请告诉博主,多谢啦~class Song;class ...
阅读全文
摘要:C++11系列-什么是C++11【Java】Final 与 C++ Const的区别C++开发者都应该使用的10个C++11特性史上最明白的 NULL、0、nullptr 区别分析C语言堆栈入门——堆和栈的区别栈空间和堆空间C++内存分配方式详解——堆、栈、自由存储区、全局/静态存储区和常量存储区A...
阅读全文
摘要:8.2 Imagine you have a call center with three levels of employees: respondent, manager, and director. An incoming telephone call must be first allocat...
阅读全文
摘要:Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted i
阅读全文
摘要:由于C++和Java都是面向对象的编程语言,它们的多态性就分别靠虚函数和抽象函数来实现。C++的虚函数可以在子类中重写,调用是根据实际的对象来判别的,而不是通过指针类型(普通函数的调用是根据当前指针类型来判断的)。纯虚函数是一种在父函数中只定义而不实现的一种函数,不能用来声明对象,也可以被称为抽象类...
阅读全文
摘要:Given an array containsNnumbers of 0 ..N, find which number doesn't exist in the array.ExampleGivenN=3and the array[0, 1, 3], return2.ChallengeDo it i...
阅读全文
摘要:在C++和java中都有枚举enum这个关键字,但是它们之间又不太一样。对于C++来说,枚举是一系列命名了的整型常量,而且从枚举值转化为对应的整型值是在内部进行的。而对于Java来说,枚举更像一个类的命名的实例,你可以自定义枚举的成员,枚举值转化为对应的整型值是再外部进行的。下面以我之前的一篇博客8...
阅读全文
摘要:8.1 Design the data structures for a generic deck of cards. Explain how you would subclass the data structures to implement blackjack.这道题让我们设计一个21点纸牌游...
阅读全文
摘要:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index. According
阅读全文
摘要:7.7 Design an algorithm to find the kth number such that the only prime factors are 3,5, and 7.这道题跟之前LeetCode的那道Ugly Number II 丑陋数之二基本没有啥区别,具体讲解可参见那篇,...
阅读全文
摘要:7.6 Given a two-dimensional graph with points on it, find a line which passes the most number of points.这道题给了我们许多点,让我们求经过最多点的一条直线。给之前那道7.5 A Line Cut ...
阅读全文
摘要:C++和Java中都有的一个静态关键字Static,可以放在类中的变量或者函数之前,就成了静态变量或者静态函数。静态变量又分为静态全局变量和静态局部变量,可参见网上大神总结的C++全局变量,局部变量,静态全局变量,静态局部变量的区别。在类中的静态变量在定义时需要用类名引导,对其访问时,使用类名或者对...
阅读全文
摘要:7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that the top and the bottom sides of th...
阅读全文