C++
此心光明存乎一心
求知路漫漫,道阻且跻,然而,此心光明即吾乡。向着心中光明之处前进吧,诸君。
展开
-
华为OJ:百钱百鸡
描述公元前五世纪,我国古代数学家张丘建在《算经》一书中提出了“百鸡问题”:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?详细描述:接口说明原型:int GetResult(vector &list)输入参数: 无输出参数(指针指向的内存区域保证有效): list 鸡翁、鸡母、鸡雏组合的列表返回值: -1 失败原创 2016-08-18 21:10:51 · 644 阅读 · 0 评论 -
leetcode:two-sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2016-08-25 20:51:52 · 264 阅读 · 0 评论 -
leetcode:search-in-rotated-sorted-array
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its转载 2016-08-25 14:41:49 · 318 阅读 · 0 评论 -
剑指offer:整数中1出现的次数(从1到n整数中1出现的次数)
求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1、10、11、12、13因此共出现6次,但是对于后面问题他就没辙了。ACMer希望你们帮帮他,并把问题更加普遍化,可以很快的求出任意非负整数区间中1出现次数。class Solution {public: int NumberOf1Between1AndN_S原创 2016-08-25 11:54:41 · 223 阅读 · 0 评论 -
剑指offer:连续子数组的最大和
原地址:http://www.nowcoder.com/questionTerminal/459bd355da1549fa8a49e350bf3df484思路:分为两种情况,最大和非负和负。若当前最大和为负,那么令sum直接等于下一个值。思路:依次读入输入数组,进行累加,动态维护和的最大值。设置两个变量,一个表示当前累加和currentSum,另一个表示子数转载 2016-08-25 10:31:59 · 357 阅读 · 0 评论 -
利用容器完成“数组中出现次数超过一半的数字”笔试题
原地址:http://www.nowcoder.com/questionTerminal/e8a1b01a2df14cb2b228b30ee6a92163参考剑指offer的答案:1.假定存在一个数val,它出现的次数超过数组元素个数和的一半2.假定val在前半部分数组中,次数小于一半,那么在后半部分,必定大于一半,然后继续将该部分二分,总有一部分会大于一半,到最后每部分元素变为两个,转载 2016-08-24 19:00:39 · 251 阅读 · 0 评论 -
剑指offer 复杂链表的复制
原地址:http://www.nowcoder.com/questionTerminal/f836b2c43afc4b35ad6adc41ec941dba输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)转载 2016-08-23 15:54:32 · 362 阅读 · 0 评论 -
leetcode: reverse-integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask befo转载 2016-08-30 00:06:21 · 355 阅读 · 0 评论 -
leetcode : jumpgame
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if yo转载 2016-08-29 16:40:42 · 358 阅读 · 0 评论 -
数据结构: 归并排序 C++
#include#include#include#include#include//#include #include using namespace std;void Merge(int a[],int tmp[],int lPos,int rPos,int rEnd){int i, lEnd, NumElements, tmpPos;原创 2016-08-18 23:45:06 · 376 阅读 · 0 评论 -
数据结构:堆排序 C++
#include#include#include#include#include//#include #include using namespace std;//堆排序/*-------------------------------------------------------------------------------------------原创 2016-08-18 23:22:11 · 362 阅读 · 0 评论 -
数据结构:直接排序法 C++
#include#include#include#include#include#include #include using namespace std;void insert_sort(int a[], int n){int j, i, temp;//精髓,抽牌的法for (i = 0; i {temp = a[i];for原创 2016-08-18 23:02:06 · 607 阅读 · 0 评论 -
数据结构:用队列实现栈 C++
//栈实现队列功能#include#include#include#includeusing namespace std;//结点class MyData{public:MyData() :data(0), next(NULL){}//默认构造函数MyData(int value) :data(value), next(NULL){}//原创 2016-08-18 22:56:17 · 653 阅读 · 0 评论 -
数据结构 栈 C++
#include#include#include#includeusing namespace std;//结点class MyData{public:MyData() :data(0), next(NULL){}//默认构造函数MyData(int value) :data(value), next(NULL){}//带参数构造函数int da原创 2016-08-18 22:47:18 · 303 阅读 · 0 评论 -
数据结构:队列
#include#include#include#includeusing namespace std;//定义结点typedef struct _Node{int data;struct _Node *next;}node;//定义队列typedef struct _Queue{//node表示元素,queue表示队列n原创 2016-08-18 22:21:49 · 316 阅读 · 0 评论 -
数据结构:单链表 C++实现
#include#include#include#includeusing namespace std;//定义ListNode类typedef struct ListNode{int data;struct ListNode *link;}ListNode;//创建链表ListNode *create(){//定义头结点、当原创 2016-08-18 21:15:18 · 439 阅读 · 0 评论 -
华为OJ:递归分苹果
题目描述把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。 输入每个用例包含二个整数M和N。0 样例输入7 3 样例输出8 /** * 计算放苹果方法数目 * 输入值非法时返回-1 * 1 * @param m 苹果数目 * @param n 盘子数目数 *转载 2016-08-18 21:13:41 · 747 阅读 · 0 评论 -
C++笔记:面向对象编程(Handle类)
句柄类句柄类的出现是为了解决用户使用指针时需要控制指针的加载和释放的问题。用指针访问对象很容易出现悬垂指针或者内存泄漏的问题。为了解决这些问题,有许多方法可以使用,句柄类就是其中之一。句柄类是一种包装类,用于存储和管理基类的对象指针,减轻用户使用对象的负担。句柄类使用指针执行操作,虚成员由于既可以指向基类型又可以指向派生类型,所以其行为将在运行时根据句柄实际绑定的对象而变化。句转载 2017-09-09 15:14:58 · 4637 阅读 · 0 评论