C/C++
文章平均质量分 67
剑侠月影
这个作者很懒,什么都没留下…
展开
-
微软经典面试题及答案
第一题 . 五个海盗抢到了100颗宝石,每一颗都一样大小和价值连城。他们决定这么分: 抽签决定自己的号码(1、2、3、4、5) 首先,由1号提出分配方案,然后大家表决,当且仅当超过半数的人同意时,按照他的方案进行分配,否则将被扔进大海喂鲨鱼,如果1号死后,再由2号提出分配方案,然后剩下的4人进行表决,当且仅当超过半数的人同意时,按照他的方案进行分配,否则将被扔入大海喂鲨鱼,依此类推原创 2014-10-21 12:16:03 · 1550 阅读 · 0 评论 -
leetcode Linked List Cycle(I II)(*)
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?原创 2014-08-12 20:26:10 · 423 阅读 · 0 评论 -
编程珠玑2.4
对于字符串,循环左移i位。比较三次旋转s原创 2014-09-09 11:40:09 · 615 阅读 · 0 评论 -
编程珠玑1.3
输入文件为包含1 000 000个整数,整数原创 2014-09-09 11:15:40 · 509 阅读 · 0 评论 -
虚函数 与 纯虚函数 区别
首先:强调一个概念定义一个函数为虚函数,不代表函数为不被实现的函数。定义他为虚函数是为了允许用基类的指针来调用子类的这个函数。定义一个函数为纯虚函数,才代表函数没有被实现。定义纯虚函数是为了实现一个接口,起到一个规范的作用,规范继承这个类的程序员必须实现这个函数。1、简介假设我们有下面的类层次:[cpp] view plaincopy转载 2014-08-23 16:20:25 · 543 阅读 · 0 评论 -
多态 和 重载的区别
多态是基于对抽象方法的覆盖来实现的,用统一的对外接口来完成不同的功能。重载也是用统一的对外接口来完成不同的功能。那么两者有什么区别呢?重载,是指允许存在多个同名方法,而这些方法的参数不同。重载的实现是:编译器根据方法不同的参数表,对同名方法的名称做修饰。对于编译器而言,这些同名方法就成了不同的方法。它们的调用地址在编译期就绑定了。多态:是指子类重新定义父类的虚方法(virtua原创 2014-08-20 09:57:04 · 963 阅读 · 0 评论 -
leetcode LRU Cache(**)
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2014-08-06 20:49:34 · 604 阅读 · 0 评论 -
leetcode Best Time to Buy and Sell Stock(I~III)(*)
I:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the原创 2014-08-05 20:51:35 · 599 阅读 · 0 评论 -
编程之美4.7蚂蚁爬杆扩展问题附猎人抓狐狸(必胜策略)
4.7节讲的是一根长27cm的木棍上,在5个点上有5只蚂蚁,蚂蚁在开始的时候朝任意方向出发,只能掉头或者往前走。让任意两只蚂蚁碰头时,它们同时掉头朝反方向走。假设蚂蚁的速度都是一秒一厘米,求蚂蚁都离开木棍的最短时间和最长时间。 穷举很麻烦,书上的思路非常精巧,即把蚂蚁碰头后掉头走,看做两个蚂蚁相遇后擦肩而过。这样就可以把蚂蚁的运动看做是独立的,是否碰头并不重要。代码也很简单,不过书上转载 2014-08-05 11:29:17 · 2280 阅读 · 0 评论 -
leetcode Length of Last Word (*)
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2014-07-28 18:52:30 · 515 阅读 · 0 评论 -
leetcode Next Permutation(*)
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible原创 2014-07-28 19:38:50 · 595 阅读 · 0 评论 -
LeetCode Divide Two Integers(***)
Divide two integers without using multiplication, division and mod operator.原创 2014-06-17 15:38:40 · 518 阅读 · 0 评论 -
leetcode Sort List(**)
Sort a linked list in O(n log n) time using constant space complexity.原创 2014-07-26 19:59:16 · 474 阅读 · 0 评论 -
leetcode Valid Sudoku(*)
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille原创 2014-07-26 20:45:17 · 515 阅读 · 0 评论 -
leetcode Insertion Sort List(*)
Sort a linked list using insertion sort. 插入排序,仿照数组的插入排序,原创 2014-07-26 20:25:41 · 507 阅读 · 0 评论 -
leetcode Reorder List(*)
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t原创 2014-08-12 20:15:59 · 472 阅读 · 0 评论 -
leetcode Populating Next Right Pointers in Each Node(*)
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.原创 2014-08-13 20:49:28 · 493 阅读 · 0 评论 -
后缀树
http://www.cppblog.com/superKiki/archive/2010/10/29/131786.aspx 在pongba的讨论组上看到一道Amazon的面试题:找出给定字符串里的最长回文。例子:输入XMADAMYX。则输出MADAM。这道题的流行解法是用后缀树(Suffix Tree)。这坨数据结构最酷的地方是用它能高效解决一大票复杂的字符串编程问题: 在文转载 2014-10-17 13:34:59 · 721 阅读 · 0 评论 -
类的直接初始化、复制初始化、赋值
一.定义区别:原创 2014-10-30 10:04:42 · 1212 阅读 · 0 评论 -
C++ Map Key值的比较操作
一.数据结构:原创 2014-10-29 17:39:51 · 4246 阅读 · 0 评论 -
leetcode Maximum Product Subarray(*)
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges原创 2014-10-10 15:06:33 · 597 阅读 · 0 评论 -
SUMMARY OF CHAPTER 1-2
CHAPTER 1SECTION 1.2 1. C++ does not directly define any statements to do input or output(IO). Instead, IO is provided by thestandard library. 2. the :: operator means the scope op原创 2012-04-08 22:45:03 · 570 阅读 · 0 评论 -
C++中的string与C中的char*
之所以抛弃char*的字符串而选用C++标准程序库中的string类,是因为他和前者比较起来,不必 担心内存是否足够、字符串长度等等,而且作为一个类出现,他集成的操作函数足以完成我们大多数情况下(甚至是100%)的需要。我们可以用 = 进行赋值操作,== 进行比较,+ 做串联(是不是很简单?)。我们尽可以把它看成是C++的基本数据类型。 首先,为了在我们的程序中使用string类型转载 2012-04-14 16:20:44 · 3957 阅读 · 0 评论 -
SUMMARY OF CHAPTER 7-8
CHAPTER 7 FUNCTIONSSECTION 7.1-7.9 1. The argument must have the same type or have a type that can be implicitly converted to the parameter type. 2. C++ is a statically type原创 2012-05-03 19:45:15 · 556 阅读 · 0 评论 -
SUMMARY OF CHAPTER 3-4
CHAPTER 3SECTION 3.1-3.5 1. the standard library defines a number of higher level abstract data types. They are abstract because when we use them we don't need to care about how the types a原创 2012-04-15 14:44:31 · 643 阅读 · 0 评论 -
常用标准库函数的常用操作记录
1.vector1) push_back() 在数组的最后添加一个数据2) pop_back() 去掉数组的最后一个数据3) at() 得到编号位置的数据4) begin() 得到数组头的指针5) end() 得到数组的最后一个单元+1的指针6) front()原创 2012-05-06 13:14:32 · 651 阅读 · 0 评论 -
MEMORY-BOOK
1.when we assign a string to a char* or an array, the length of char* or array should be 1 more than the size of string, ending with '\0'. However, the end of string does not have '\0'. int m原创 2012-04-10 22:08:52 · 672 阅读 · 0 评论 -
SUMMARY OF CHAPTER 5-6
CHAPTER 5SECTION 5.1-5.12 1. % operator can be applied only to operands of the integral types: bool, char, short, int, long, and their associated unsigned types. 2. When only one o原创 2012-04-22 22:51:58 · 573 阅读 · 0 评论 -
PAT 1010
#include using namespace std;long long int toD(string str,long long int radix){ long long int num=0; for(int i=0;i<str.length();i++){ if(str[i]>='a'&&str[i]<='z'){ num=nu原创 2014-08-30 21:03:18 · 544 阅读 · 0 评论 -
C++拷贝构造函数详解
一. 什么是拷贝构造函数首先对于普通类型的对象来说,它们之间的复制是很简单的,例如:[c-sharp] view plaincopyint a = 100; int b = a; 而类对象与普通对象不同,类对象内部结构一般较为复杂,存在各种成员变量。下面看一个类对象拷贝的简单例子。转载 2014-08-17 14:08:22 · 537 阅读 · 0 评论 -
leetcode Palindrome Partitioning(*)
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2014-08-14 20:13:53 · 529 阅读 · 0 评论 -
LeetCode Palindrome Partitioning II(***)
Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning ofs.For example, given s = "aab",Retur原创 2014-06-13 21:56:48 · 545 阅读 · 0 评论 -
CareerCup chapter 2 Linked Lists
1.Write code to remove duplicates from an unsorted linked list FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?原创 2014-06-02 10:24:09 · 722 阅读 · 0 评论 -
CareerCup chapter 3 Stacks and Queues
Implement a stack template class t原创 2014-06-02 17:14:00 · 1181 阅读 · 0 评论 -
Leetcode Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".class Solution {public: string addBinary(string a, string b) { if(a.原创 2014-06-11 19:28:52 · 598 阅读 · 0 评论 -
CareerCup chapter 1 Arrays and Strings
1.Implement an algorithm to determine if a string has all unique characters What if you can not use additional data structures?The le2.原创 2014-05-29 11:30:07 · 1499 阅读 · 0 评论 -
Leetcode Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".click to show clarification.Clarification:What constitutes a word?原创 2014-06-11 15:42:21 · 617 阅读 · 0 评论 -
Leetcode Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.Each number in C may only be used once in the combinat原创 2014-06-11 16:58:53 · 481 阅读 · 0 评论 -
Leetcode Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.di原创 2014-06-11 16:29:51 · 1195 阅读 · 0 评论 -
CareerCup chapter 5 Bit Manipulation
5.1 You are given two 32-bit numbers, N and M, and two bit positions, i and j Write a method to set all bits between i and j in N equal to M (e g , M becomes a substring of N located at i and starting原创 2014-06-07 09:58:42 · 722 阅读 · 0 评论