C++
文章平均质量分 64
再度飞越
这个作者很懒,什么都没留下…
展开
-
计算N阶乘中结尾有多少零
ProblemWrite an algorithm which computes the number of trailing zeros in n factorial.Solution#include using namespace std;int main(int argc, char* argv[]){ int n = 100; int m =原创 2013-05-17 09:34:41 · 817 阅读 · 0 评论 -
面试 改错题-2
ProblemFind as many issues as possible and correct them:char *GenerateRandomString(void){ int i; char RandomString[10]; for(i = 0; i <= 10; i++) { RandomString[i] = ra原创 2013-05-15 12:17:11 · 1088 阅读 · 1 评论 -
面试 改错题-1
ProblemFind as many issues as possible and correct them:malloc(n) allocates n bytes in the heap.int main(void){ int *ptr = (int *) malloc(10); for(int i =0; i <10; i++) {原创 2013-05-15 11:29:39 · 1051 阅读 · 1 评论 -
计算计算机字节顺序
ProblemWrite a function that determines whether a computer is big-endian or little-endianSolution#include using namespace std;int is_little_endian(){ int num = 0x1; char *p = (c原创 2013-05-14 12:53:09 · 689 阅读 · 0 评论 -
如何使用堆栈实现队列
ProblemHow to use two stacks to implement a queueSolutionIt is simple, just serialize two stacks #include #include using namespace std;stack s1;stack s2;bool que_add(int value){原创 2013-05-15 08:32:07 · 834 阅读 · 1 评论 -
使用1-5随机数生成器产生1-7的随机数(Google Technical Interview)
ProblemGenerate random between 1..7(Google Technical Interview).Write a method to generate a random number between 1 and 7, given a method that generates a random number between 1 and 5 (i. e. , imp原创 2013-05-15 08:20:44 · 1525 阅读 · 1 评论 -
查找数组中的缺失的2个数字
ProblemTwo numbers are missing from the first hundred numbers. They are NOT sorted. How to find them? You can't sort.. and can't iterate one by one.. has to be less than O(N)? Can't use stack , se原创 2013-06-03 08:46:29 · 2133 阅读 · 0 评论 -
Detect whether two rectangles have common area or not -- Amazon
ProblemWrite a function to check if two rectangles defined as below, have common area or not. The functions take the top left and bottom right coordinate as input and return 1 if the原创 2013-06-19 12:50:38 · 703 阅读 · 0 评论 -
Find pairs equal zero -- Paypal
ProblemGiven 2 equal-length arrays of integers, find pairs, one from each array, that sum to 0. -- note that one wrinkle of this problem over the more usual form, which is to do this in a si原创 2013-06-19 12:53:28 · 564 阅读 · 0 评论 -
Find the maximum contiguous subsequence product -- InMobi
ProblemSuppose you have an array of +ve numbers, -ve numbers and zeroes. Devise an algorithm to find the maximum contiguous subsequence product. For 7 -3 -1 2 -40 0 3 6, the max subsequence prod原创 2013-06-19 12:55:40 · 705 阅读 · 0 评论 -
八皇后问题
ProblemPlace eight queens on an 8×8 chessboard so that no two queens attack each other.Solution// EightQueens.cpp : Defines the entry point for the console application.//#include #include原创 2013-05-14 11:31:04 · 489 阅读 · 0 评论 -
删除链表中一个位于中间位置的节点
ProblemDelete a node in the middle of list, given only access list onceSolution#include using namespace std;typedef struct linked_list{ int data; struct linked_list *next;}Linked_原创 2013-05-14 13:51:20 · 684 阅读 · 3 评论 -
将一个方阵旋转90度
ProblemRotate a matrix by 90 degrees anti-clockwiseSolution#include using namespace std;int** create_matrix(int row, int col){ int **m = new int* [row]; for(int i = 0; i < row;原创 2013-05-14 13:30:27 · 707 阅读 · 0 评论 -
计算两个字符串链表中的共同数据项,需要考虑重复选项的情况
Problem/*// Given two lists of strings build a new list that has all strings that appear in both the original lists. If the same string appears more than once output it as many times as it appea原创 2013-05-22 06:03:55 · 820 阅读 · 2 评论 -
转置整数方阵
ProblemTranspose an integer arraySolution#include using namespace std;int** create_matrix(int row, int col){ int **m = new int* [row]; for(int i = 0; i < row; i++){ m[i] =原创 2013-05-22 06:09:09 · 892 阅读 · 1 评论 -
联合体问题
QuestionGiven the definitions below, which of the follow statements are correct?union{ union{ int a; int b; int c; }abc, xyz;}first, second;A. &sec原创 2013-05-14 13:43:10 · 745 阅读 · 1 评论 -
内存分配中的对齐操作
ProblemMemory operation with alignmentSolution#include using namespace std;int aligned_malloc(void **memptr, size_t alignment, size_t size){ size_t len = size + al原创 2013-05-27 05:32:42 · 779 阅读 · 0 评论 -
计算一个数是不是2的幂
ProblemGiven a number, determine whether it is a power of 2Solutionbool is_power_2(int n){ return ((n & (n-1)) == 0)? true : false;}int main(int argc, char *argv[]){ for(int i = 0原创 2013-05-14 13:12:15 · 530 阅读 · 0 评论 -
汉诺塔
ProblemOnly one disk may be moved at a time.Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present原创 2013-05-14 13:37:19 · 481 阅读 · 0 评论 -
寻找字典中变位词
问题Given a dictionary of English words, return the set of all words grouped into subsets of words that all anagrams of each other.方案// FindAnagrams.cpp : Defines the entry point for the conso原创 2013-05-14 12:17:06 · 572 阅读 · 0 评论 -
全排列
ProblemPrint all permutations of n distinct elements.Solution// Permutaion.cpp : Defines the entry point for the console application.//#include #include #include using namespace std;v原创 2013-05-14 16:58:12 · 495 阅读 · 1 评论 -
Swap kth element from the beginning and kth element from the end of linked list -- Amazon
转载自:https://sites.google.com/site/spaceofjameschen/homeProblemSwap kth element from the beginning and kth element from the end of linked list.Solution/* ===========================转载 2013-06-22 13:04:56 · 629 阅读 · 0 评论