自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(32)
  • 资源 (2)
  • 收藏
  • 关注

原创 careercup5.7

/*An array A[1 n] contains all the integers from 0 to n except for one number which is missing In this problem, we cannot access an entire integer in A with a single opera-tion The elements of

2012-05-20 00:40:09 465

原创 careercup5.6

/*Write a program to swap odd and even bits in an integer with as few instructions aspossible (e g , bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, etc) */#include #include using names

2012-05-18 10:13:15 336

原创 careercup5.5

/*Write a function to determine the number of bits required to convert integer A to integer B Input: 31, 14Output: 2*/#include #include using namespace std;int main(){ int a = 31,b = 14, co

2012-05-17 10:14:33 313

原创 careercup5.3

把第一个过0的1设成0,最后一个0设成1,再把其他数按小的放即为last把第一个过1的0设成1,最后一个1设成0,再把其他数按大的放即为next/*Given an integer, print the next smallest and next largest number that have the same number of 1 bits in their binary rep

2012-05-15 10:20:10 623

原创 careercup5.2

判错搞麻烦了。。/*Given a (decimal - e g 3 72) number that is passed in as a string, print the binary rep-resentationIf the number can not be represented accurately in binary, print “ERROR” */#include

2012-05-14 12:05:01 518

原创 careercup5.1

本来是用字符串做的,后来看见答案用位运算做,就用bitset做了一下。/*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 sub

2012-05-13 10:32:26 505

原创 careercup4.8

在data外扩展一个val域,记录要累加的值,通过中序遍历递归,在一个以深度为长度的数组中,更新记录每一个path的所有和值。等于result就打印。/*You are given a binary tree in which each node contains a value Design an algorithm to print all paths which sum up to

2012-05-12 16:39:27 552

原创 careercup4.7

深搜,再匹配/*Given a binary search tree, design an algorithm which creates a linked list of all thenodes at each depth (eg, if you have a tree with depth D, you’ll have D linked lists) */#include #

2012-05-11 09:49:54 502

原创 careercup4.6

类似于哈夫曼树的编码形式,对树编码,左子树0,右子树1。对树进行深搜,找到最长匹配串就是最优公共父节点。/*Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree Avoid storing additional nodes in a data st

2012-05-10 10:24:14 475

原创 careercup4.5

/*Write an algorithm to find the ‘next’ node (i e , in-order successor) of a given node in a binary search tree where each node has a link to its parent*/#include #include #include using namespa

2012-05-09 11:07:05 487

原创 careercup4.4

层序稍微变一下。。/*Given a binary search tree, design an algorithm which creates a linked list of all thenodes at each depth (eg, if you have a tree with depth D, you’ll have D linked lists) */#include

2012-05-08 10:40:11 908

原创 careercup4.3

插入最中点/*Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height */#include #include using namespace std;class Node{public: int data; Node

2012-05-07 14:33:52 414

原创 careercup4.2

看连通性当然深搜广搜都可以,当然深搜代码更简单。/*Given a directed graph, design an algorithm to find out whether there is a route be -tween two nodes*/#include #include #define N 6using namespace std;bool dfs(int

2012-05-06 11:27:17 491

原创 careercup4.1

二叉树的基本操作,就在前序遍历中插入高度更新即可。/*Implement a function to check if a tree is balanced For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in dis

2012-05-05 11:44:30 531

原创 careercup3.6

把全局的排序做成每个子问题的排序,每次出来的一个数都会排好序。/*Implement a MyQueue class which implements a queue using two stacks*/#include using namespace std;class Node{public: int data; Node* next; Node(){this->ne

2012-05-04 15:53:43 414

原创 careercup3.5

有一个调整函数。Intoout,/*Implement a MyQueue class which implements a queue using two stacks*/#include using namespace std;class Node{public: int data; Node* next; Node(){this->next = 0;} Node(

2012-05-03 17:53:46 352

原创 careercup3.4

经典的汉诺塔问题/*In the classic problem of the Towers of Hanoi, you have 3 rods and N disks of different sizes which can slide onto any tower The puzzle starts with disks sorted in ascending order of s

2012-05-02 09:42:09 400

原创 careercup3.3

没有太多技巧,但感觉程序有点乱。当然用vector中总是随机访问代价其实还是不小的(虽然是O(1)),数据大会很慢,还是数组好。。总之。。。劳动节码代码最光荣/*Imagine a (literal) stack of plates If the stack gets too high, it might topple There-fore, in real life, we wou

2012-05-01 13:16:12 465

原创 careercup3.2

基本操作。/*How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min should all operate in O(1) time*/#include us

2012-04-30 14:17:45 504

原创 careercup2.5

Given a circular linked list, implement an algorithm which returns node at the begin-ning of the loop DEFINITION Circular linked list: A (corrupt) linked list in which a node’s next pointer poin

2012-04-28 16:36:34 396

原创 careercup2.4

/*You have two numbers represented by a linked list, where each node contains a sin-gle digit The digits are stored in reverse order, such that the 1’s digit is at the head of the list Write a f

2012-04-28 15:28:05 345

原创 careercup2.3

删除~/*Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node EXAMPLEInput: the node ‘c’ from the linked list a->b->c->d->eResult: nothing is

2012-04-26 10:35:33 326

原创 careercup2.2

挺简单,两个指针差n扫描。/*Implement an algorithm to find the nth to last element of a single linked list*/#include using namespace std;class Node{public: int data; Node* next; Node(){this->next = 0;

2012-04-25 10:02:11 267

原创 careercup2.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?*/#include using namespace std;class Node{

2012-04-24 11:07:30 442

原创 careercup8

copy一次字符串即可/*Assume you have a method isSubstring which checks if one word is a substring of another Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using

2012-04-23 12:17:56 319

原创 careercup7

记录0位置,最后一次清零。否则前面清0后面无法正确判断是否是原有的0./*Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0*/#include #define N 4#define M 4using namespace std

2012-04-22 13:58:10 304

原创 careercup6

逆时针转圈,4个数为一组,由外到内一圈圈转。关键在于准确记录四个数的下标位置。用了六个小数组,当然四个也可以。offset_x是用来记录初始位置。p,q记录每一圈开始时的偏移量,x,y记录在圈内转动循环时的偏移量。/*Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes,

2012-04-21 15:52:42 409

原创 careercup5

Write a method to replace all spaces in a string with ‘%20’还是用比较核武的字符串流吧~~刚开始的题目还是比较简单的。#include #include #include using namespace std;int main(){ string st,buff; getline(cin ,st);

2012-04-20 10:08:42 365

原创 careercup1

由于只能在源字符串中操作,所以要靠排序,快排中如果跟pivot相同就失败。/* Inpmlemement an algorithm to determine if a string has all unique characters What if you can not use additional data structures? */#include #include

2012-04-19 11:54:42 277

原创 careercup2

/*Write code to reverse a C-Style String (C-String means that “abcd” is represented as five characters, including the null character )*/#include #include #include using namespace std;int main

2012-04-19 11:52:13 313

原创 careercup3

/*Design an algorithm and write code to remove the duplicate characters in a stringwithout using any additional buffer NOTE: One or two additional variables are fineAn extra copy of the array is n

2012-04-19 11:47:29 236

原创 careercup4

/*Write a method to decide if two strings are anagrams or not*/#include #include using namespace std;bool JudgeAnagrams(string s1, string s2){int st1[256],st2[256];if(s1.length() != s2.leng

2012-04-19 11:44:12 454

Instructor's Manual for C++ How to Program

Instructor's Manual for C++ How to Program

2012-02-10

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除