C++多重继承时调用相应的父类函数
摘要:C++中没有super或parent关键字,想要调父类方法,只能使用明确的[父类名称::方法名]假如要求A和B是C的父类的前提下,要使如下代码能够分别输出A和B的相关信息(虽然这个要求很少遇到....,但是面试官就是这么变态)int main(int argc, char* argv[]){ C c; A* pA = &c; B* pB = &c; pA->foo(); //这里会输出和A相关的信息 pB->foo(); //这里会输出和B相关的信息 return 0;} 怎么办?// test.cpp : Defines the entry poi...
阅读全文
posted @
2013-10-17 01:31
yangyh
阅读(5656)
推荐(0)
笔试题:二叉树按层遍历&添加兄弟指针&求LCA&排序二叉树的查找
摘要:1.二叉树按层遍历2.二叉树添加兄弟指针3.在二叉树中查找LCA(最近公共祖先)3.在排序二叉树中找到大于N且最接近N的数// PrintByLevel.cpp : Defines the entry point for the console application.// Author : yangyh#include "stdafx.h"#include <iostream>#include <queue>using namespace std;typedef struct _node_st{ int value; _node_st* pLeft
阅读全文
posted @
2011-09-29 21:03
yangyh
阅读(1242)
推荐(1)
递归系列:分解质因数
摘要:void toPrimMulti(int n, int m) { if (n >= m) { while (n % m != 0) m++; n /= m; printf("%d ", m); toPrimMulti(n, m); }}toPrimMulti(21, 2);
阅读全文
posted @
2011-08-10 01:33
yangyh
阅读(537)
推荐(0)
组合问题(递归)
摘要://============================================================================// Name : ForJob.cpp// Author : yangyh// Version :// Copyright : Your copyright notice// Description : Hello World in C++, Ansi-style//============================================================================//从M个字符中选出N
阅读全文
posted @
2011-08-10 01:04
yangyh
阅读(471)
推荐(0)
一道关于C++ 继承/虚函数 笔试题
摘要:#include "stdafx.h"#include "stdio.h"#include "string.h"class Father{public: name() {printf("father name\n");}; virtual call() {printf("father call\n");}; };class Son: public Father{public: name() {p...
阅读全文
posted @
2011-06-04 01:06
yangyh
阅读(1967)
推荐(1)
POJ1328 qsort
摘要:至于很多朋友说这道题快排为什么不行,请看qcmp函数,返回1与-1 // Rader.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <algorithm> #include <math.h> #include <iostream> using namespace ...
阅读全文
posted @
2011-04-29 20:19
yangyh
阅读(183)
推荐(0)
POJ2965(TLE,Why?)
摘要:#include <stdafx.h> #include <iostream> #define MAX_STATE 65535 #define ALL_BLACK 65535 #define ALL_WHITE 0 #define WIDTH 4 #define HEIGTH 4 #define SIZE_OF_BOARD WIDTH*HEIGTH #include <queue> using n...
阅读全文
posted @
2011-04-29 13:50
yangyh
阅读(232)
推荐(0)
使用getopt_long解析程序长选项参数
摘要:写在前面:对于可选参数一定要使用以下两种方法标明其值 –wValue 或--who==Value 而不能是 --who Value,而对于必填参数则可以使用-lValue 或 --love Value或--love=Value,这并不是bug.//============================================================================// Name : TestOpt.cpp// Author : yangyh// Version :// Copyright : Your copyright notice// Descriptio
阅读全文
posted @
2011-03-20 23:00
yangyh
阅读(731)
推荐(1)
VC:杀死进程
摘要:BOOL KillProcessFromName(LPCSTR lpProcessName){ HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 pe; pe.dwSize = sizeof(PROCESSENTRY32); if(!Process32First(hSnapShot,&pe)) { return FALSE; } string strProcessName = lpProcessName; // strProcessName.MakeLower(); wh
阅读全文
posted @
2011-03-09 20:57
yangyh
阅读(2498)
推荐(0)
C base64 编码文件
摘要:功能:读取二进制文件,转化为BASE64编码字符串,文件会增大1/3,详见BASE64编码原理,这样就可以在帖子中保存文件了,没办法,公司不许上传附件,POST也只能一次6KB,之前还写了一个模拟HTTP发送的程序(http://www.cnblogs.com/yangyh/archive/2010/07/21/1781845.html),实为CNBLOG的小组自动提交程序,不过现在CNBLOG添加了防ROBOT功能了,一次只能发32帖了
阅读全文
posted @
2011-01-19 21:52
yangyh
阅读(2399)
推荐(0)
系统服务启动交互式程序(C++)
摘要:KEY: CreateProcessAsUser, service GUI interactive, C++ 启动进程用于xp,server 2003,不适用于vista以上(http://blog.csdn.net/zhyRzfirst/archive/2009/03/16/3994344.aspx,http://www.codeproject.com/KB/vista-security/VistaSessions.aspx,可遍历WTSEnumerateSessions获取活跃桌面后设置STARTUPINFO参数中的lpDesktop参数)CreateProcessAsUser 1314错
阅读全文
posted @
2010-12-28 23:12
yangyh
阅读(2367)
推荐(1)
sprintf笔记
摘要:int t=10; char str1[5]; sprintf(str1,"%#04x",t);//#表示添加0x,0表示补0,4表示补足4位
阅读全文
posted @
2010-12-27 17:49
yangyh
阅读(166)
推荐(0)
c debug代码
摘要:#define DEBUG 1#define debug(format, ...) do{if(DEBUG)fprintf (stdout, format, ## __VA_ARGS__);}while(0)通用版:#define DEBUG#include <stdarg.h>int debug(const char *fmt, ...){ #ifdef DEBUG char printf_buf[1024]; va_list args; int printed; va_start(args, fmt); printed = vsprintf(printf_buf, fmt, a
阅读全文
posted @
2010-07-17 01:50
yangyh
阅读(1119)
推荐(0)
TINYXPATH (转)
摘要:TinyXPath examples / regression testsInput XML tree<a><b val='123'><b /><c /><!-- -122.0 --><d /></b><!-- 500.0 --><x target='xyz'>sub text </x...
阅读全文
posted @
2010-07-08 09:39
yangyh
阅读(559)
推荐(0)
linux c 唤醒进程 获取子进程结束状态
摘要:void don(int sig) { printf("rece sig %d\n"); }void testwake(){ int pid; int p=getpid(); pid=fork(); if(pid==0){ printf("child before\n"); sleep(3); kill(p,SIGUSR1); }else{ signal(SIGUSR1,don); sleep(...
阅读全文
posted @
2010-07-07 21:38
yangyh
阅读(1862)
推荐(0)
Linux c 获取系统内存
摘要:void getSystemMemoryInfo(char* MemTotal,char*MemFree){ char total[60],free[60],temp[60]; char infile[15]="/proc/meminfo"; // char unit[4]="kB"; FILE * fp; int i,j; if((fp=fopen(infile,"r"))==NULL)...
阅读全文
posted @
2010-07-04 02:39
yangyh
阅读(2216)
推荐(0)
Linux c 共享内存
摘要:#include <sys/types.h>#include <sys/ipc.h>#include <sys/shm.h>#include <stdio.h>#include <stdlib.h>typedef struct { int islock;} VMMSHM;int deleteShareMem() { int shm_id;...
阅读全文
posted @
2010-06-30 19:50
yangyh
阅读(902)
推荐(0)
C Socket 发送/接收数据结构
摘要:typedef struct {char s[20];int i;float f;} S;S *s=(S*)malloc(sizeof(S)); Sendto(sockfd, s, sizeof(S), 0, pservaddr, servlen); Recvfrom(sockfd, s, sizeof(S), 0, pcliaddr, &len); printf("receive:%lf...
阅读全文
posted @
2010-06-23 22:22
yangyh
阅读(1856)
推荐(0)
Tinyxml 示例
摘要:int add(const char* ip,const char* name){TiXmlDocument vmmdoc("vmmconfig.xml");TiXmlNode *phy;bool loadOkay = vmmdoc.LoadFile();if ( !loadOkay ){printf( "Could not load test file 'vmmconfig.xml'. Erro...
阅读全文
posted @
2010-06-23 21:47
yangyh
阅读(286)
推荐(0)