OJ
zbxzc
这个作者很懒,什么都没留下…
展开
-
VC启动一个新线程的三种方法
主要用AfxBeginThread()函数来UINT myproc(LPVOID lParam){CITTDlg *pWnd = (CITTDlg *)lParam;pWnd->KMeansSegment();return 1;}void CITTDlg::KMeansSegment(){// 主要处理函数在这里写}voi原创 2015-03-14 19:53:43 · 17207 阅读 · 2 评论 -
添加自定义消息处理
1.PreTranslateMessagePreTranslateMessage是消息在送给TranslateMessage函数之前被调用的。头文件中重载该函数virtual BOOL PreTranslateMessage(MSG* pMsg);源文件中写实现方法BOOL CClientDlg::PreTranslateMessage(MSG* pMsg) {原创 2015-03-15 01:02:02 · 1144 阅读 · 0 评论 -
VC编程小技巧
1.rich edit控件使用时需要初始化用vc新建dialog.添加rich edit 后编译可以通过,运行后自动退出,原因即是没有初始化的后果。解决方法:AfxInitRichEdit(); CWinApp::InitInstance();必须在CWinApp::InitInstance(); 之前。2.socket原创 2015-03-14 18:34:04 · 647 阅读 · 0 评论 -
VC如何对新创建的一个线程暂停或重启
执行AfxBeginThread()函数时,如果成功则返回一个指向新线程对象的CWinThread指针,否则为NULL。这样只要得到这一新线程的指针,我们就可以对新线程进行操作了。向对话框类里面添加一个CWinThread* mythread 的成员变量,不用初始化为NULL,这样会报错的,因为它只能通过AfxBeginThread函数获得。然后添加一个 pause 按钮向其响应函数里原创 2015-03-14 20:36:53 · 2098 阅读 · 0 评论 -
c++ 定时器使用
转自:http://blog.163.com/linzuxin@126/blog/static/340740572008101311552948/1.1 用WM_TIMER来设置定时器 先请看SetTimer这个API函数的原型 UINT_PTR SetTimer( HWND hWnd, // 窗口句柄 UINT_PTR nIDEvent,转载 2015-05-15 11:44:37 · 4281 阅读 · 0 评论 -
Cstring转char、string、int等数据类型的方法
转自:http://blog.csdn.net/jax_lee/article/details/6764331CString 转char *CString cstr;char *p = (LPSTR)(LPCTSTR)cstr;string 转 CStringCString.format(”%s”, string.c_str());char 转 CS转载 2015-05-15 13:43:56 · 951 阅读 · 0 评论 -
C++中引用(&)的用法和应用实例
转自:http://www.cnblogs.com/Mr-xu/archive/2012/08/07/2626973.html对于习惯使用C进行开发的朋友们,在看到c++中出现的&符号,可能会犯迷糊,因为在C语言中这个符号表示了取地址符,但是在C++中它却有着不同的用途,掌握C++的&符号,是提高代码执行效率和增强代码质量的一个很好的办法。在 c++学习提高篇(3)---隐式指针的转载 2015-06-03 08:26:04 · 449 阅读 · 0 评论 -
VS2013常见错误排查
1. CMemDC重定义1>nafxcwd.lib(afxglobals.obj) : error LNK2005: "public: virtual __thiscall CMemDC::~CMemDC(void)" (??1CMemDC@@UAE@XZ) 已经在 DMGraphicView.obj 中定义原因:上面是意思是,连接器说,我找到了两个定义,一个在 uafxcwd.lib(a原创 2015-03-28 21:24:39 · 4565 阅读 · 0 评论 -
创建自己的窗口消息
步骤1. 创建一个新的窗口消息使用以下方式定义一个新的消息。若想定义多个消息,只要使用WM_USER的更大增量即可。# define WM_WZD_MESSAGE WM_USER+12. 发送一个新的窗口消息利用SendMessage( )发送新消息:AfxGetMainWnd( )-> SendMessage (WM_WZD_MESSAGE, wParam, lP原创 2015-05-24 10:46:10 · 631 阅读 · 0 评论 -
进程间通信——使用WM_COPYDATA消息通信
使用SendMessage向另一进程发送WM_COPYDATA消息发送WM_COPYDATA消息SendMessage(接收窗口句柄, WM_COPYDATA, (WPARAM)发送窗口句柄, (LPARAM)©Data);copyData是要发送的数据,类型为COPYDATASTRUCT结构体typedef struct tagCOPYDATA原创 2015-07-01 14:13:47 · 2366 阅读 · 0 评论 -
进程间通信——管道通信
Windows系统编程之进程间通信作者:北极星2003来源:看雪论坛(www.pediy.com)附件:windowipc.rar Windows 的IPC(进程间通信)机制主要是异步管道和命名管道。(至于其他的IPC方式,例如内存映射、邮槽等这里就不介绍了)管道(pipe)是用于进程间通信的共享内存区域。创建管道的进程称为管道服务器,而连接到这个管道的进程称为管道客户转载 2015-07-01 15:18:45 · 663 阅读 · 0 评论 -
判断二叉树是不是平衡二叉树
输入一棵二叉树的根结点,判断该树是不是平衡二叉树。如果某二叉树中任意结点的左右子树的深度相差不超过1,那么它就是一棵平衡二叉树。例如下图中的二叉树就是一棵平衡二叉树:原创 2015-07-08 23:02:07 · 879 阅读 · 0 评论 -
判断IP地址是否有效
IP的有效值是1.0.0.1~255.255.255.255,写个程序,参数是一个char*的IP,返回这个IP是否有效。// IPcheck.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#includeusing namespace std;//IP的有效值是1.0.0.1~255.255.255.255bool checkIP(c原创 2015-07-07 23:45:30 · 7203 阅读 · 0 评论 -
进程间通信——内存映射
进程1的数据有时需要发送给进程B,这可以通过内存映射实现。主要用到的函数:1.首先在一个进程里用CreateFileMapping创建一个新的文件映射内核对象。HANDLE CreateFileMapping( HANDLE hFile, //物理文件句柄,一般将它设原创 2015-03-17 21:45:26 · 1282 阅读 · 0 评论 -
最大递增数
输入一串数字,找到其中包含的最大递增数。递增数是指相邻的数位从小到大排列的数字。如: 2895345323,递增数有:289,345,23, 那么最大的递增数为345。运行时间限制:无限制内存限制:无限制输入:输入一串数字,默认这串数字是正确的,即里面不含有字符/空格等情况输出:输出最大递增数样例输入:123526897215样例输出:2689// MaxIncreseNum.cpp原创 2015-07-02 09:05:26 · 966 阅读 · 0 评论 -
华为笔试
void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);bool search(vector&p, char a);int _tmain(int argc, _原创 2015-07-01 23:14:14 · 531 阅读 · 0 评论 -
如何将两个有序的一维数组合并为一个有序的一维数组合
如何将两个有序的一维数组合并为一个有序的一维数组合// merge_array.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include#includeusing namespace std;void insert(listpp, int num);int _tmain(int argc, _TCHA原创 2015-07-02 22:31:01 · 4807 阅读 · 0 评论 -
单词统计
单词统计题目描述: 输入一段英文文本,用程序统计出现频率最高和最低的两个单词; 英文文本中仅出现这四类字符:空格( )、英文逗号(,)、英文句号(.)、英文大小写字母(a-z、A-Z) 单词之间的分隔符仅考虑这三种:空格( )、英文逗号(,)、英文句号(.); 仅大小写不同的单词算同一个单词; 如果两个单词出现次数相同,则在文本中首次出现的单词优先返回。 返回的单词统一用小写原创 2015-07-12 13:45:52 · 1174 阅读 · 0 评论 -
关于strncpy函数
转自:http://www.cnblogs.com/unimous/archive/2012/03/05/2381151.htmlC/C++中的strncpy()函数功能为将第source串的前n个字符拷贝到destination串,原型为:char * strncpy ( char * destination, const char * source, size_t num );转载 2015-07-11 21:36:59 · 622 阅读 · 0 评论 -
求子数组的最大和
题目: 输入一个整形数组,数组里有正数也有负数。 数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和。 求所有子数组的和的最大值。要求时间复杂度为O(n)。 例如输入的数组为1, -2, 3, 10, -4, 7, 2, -5,和最大的子数组为3, 10, -4, 7, 2, 因此输出为该子数组的和18。原创 2015-07-04 13:02:22 · 533 阅读 · 0 评论 -
数组交换
有两个序列a,b,大小都为n,序列元素的值任意整数,无序;要求:通过交换a,b中的元素,使[序列a元素的和]与[序列b元素的和]之间的差最小。例如: var a=[100,99,98,1,2, 3];var b=[1, 2, 3, 4,5,40];// exchange_array.cpp : 定义控制台应用程序的入口点。//#include "stdaf原创 2015-07-03 11:56:06 · 774 阅读 · 0 评论 -
VS2013各种类型转换
1.CString到const char *的转换 const char * a; CString b; //a=b;//不存在从CSring到const char *的适当转换函数 a=(const char *)b.GetBuffer(); 2.从const char [ ]转换为const wcha原创 2015-03-14 14:29:22 · 11546 阅读 · 0 评论 -
超级台阶
描述有一楼梯共m级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第m级,共有多少走法?注:规定从一级到一级有0种走法。输入输入数据首先包含一个整数n(1输出对于每个测试实例,请输出不同走法的数量。样例输入223样例输出12很明显,递归思想// Goupstairs.cpp : 定义控制台应用程序的入口点原创 2015-07-06 22:36:53 · 539 阅读 · 0 评论 -
链表排序、链表删除、访问倒数第k个节点
1.设一个带头结点的单向链表的头指针为head,设计算法,将链表的记录,按照data域的值递增排序。2.已知线性表中的元素以单链表作存储结构。试写一算法,删除表中所有大于x且小于y的元素(若表中存在这样的元素)同时释放被删除结点空间。3.输出该链表中倒数第k个结点, tail为倒数第0个节点//#include "stdafx.h"#includeusing na原创 2015-07-07 13:12:41 · 1372 阅读 · 0 评论 -
二叉树宽度的计算
二叉树的宽度定义为具有最多结点数的层中包含的结点数,试计算一二叉树的深度。#include "stdafx.h"#include #includeusing namespace std;struct BiNOde{ int ele; BiNOde* lnode; BiNOde* rnode;};vectoraa;int maxdepth = 0;原创 2015-07-15 04:31:20 · 1797 阅读 · 0 评论 -
大数阶乘
描述我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?输入输入一个整数m(0输出输出m的阶乘,并在输出结束之后输入一个换行符样例输入50样例输出30414093201713378043612608166064768844377641568960512000000000000原创 2015-07-05 09:18:10 · 493 阅读 · 0 评论 -
leetcode 327. Count of Range Sum
Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the elements in nums between indices i and j (i ≤ j), inc原创 2016-01-25 19:47:05 · 1657 阅读 · 0 评论 -
leetcode 233. Number of Digit One
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in the follow原创 2016-03-02 17:04:51 · 563 阅读 · 0 评论 -
leetcode 230. Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total elements.Follow up:What if t原创 2016-03-02 17:50:57 · 447 阅读 · 0 评论 -
leetcode 214. Shortest Palindrome
Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.For ex原创 2016-03-02 23:55:18 · 491 阅读 · 0 评论 -
leetcode 324. Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] nums[2] Example:(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1, 3, 2, 2, 3, 1原创 2016-03-03 11:38:24 · 832 阅读 · 0 评论 -
leetcode 221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0原创 2016-03-03 14:27:04 · 499 阅读 · 0 评论 -
leetcode 49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note:原创 2016-03-15 21:34:09 · 520 阅读 · 0 评论 -
leetcode 45. Jump Game II
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.Your goal i原创 2016-03-15 23:14:08 · 313 阅读 · 0 评论 -
leetcode 335. Self Crossing
You are given an array x of n positive numbers. You start at point (0,0) and moves x[0] metres to the north, then x[1] metres to the west, x[2] metres to the south, x[3] metres to the east and s原创 2016-03-04 09:48:00 · 1033 阅读 · 0 评论 -
leetcode 331. Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #.原创 2016-03-04 11:36:19 · 729 阅读 · 0 评论 -
leetcode 240. Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in原创 2016-03-03 18:47:37 · 508 阅读 · 0 评论 -
leetcode 239. Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window m原创 2016-03-04 13:28:44 · 398 阅读 · 0 评论 -
leetcode 209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3原创 2016-03-04 15:06:47 · 467 阅读 · 0 评论 -
leetcode 216. Combination Sum III
class Solution { void do_once(int k,int n, map, int>&candi) { map, int>newcandi; for (map, int>::iterator it = candi.begin(); it != candi.end(); it++) { if (k == 1) { if (n - it->sec原创 2016-03-16 20:01:03 · 437 阅读 · 0 评论