自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(47)
  • 收藏
  • 关注

原创 智力题:比赛问题

宿舍内5个同学一起玩对战游戏。每场比赛有一些人作为 红方,另一些人作为蓝方。请问至少需要多少场比赛, 才能使任意两个人之间有一场红方对蓝方和蓝方对红 方的比赛?

2015-07-31 11:32:09 1200

原创 算法题:链表的递归逆序

#include <iostream>using namespace std;struct Node{ int data; Node *next; Node(int d = int()) :data(d), next(NULL){}};class Clist{public: Clist(int a[], int n) :first(NULL) {

2015-07-31 10:12:21 798

原创 算法题:求解两个链表的交集

/*已知集合A和B的元素分别用不含头结点的单链表存储,函数difference()用于求解集合A与B的差集,并将结果保存在集合A的单链表中。例如,若集合A = { 5, 10, 20, 15, 25, 30 },集合B = { 5, 15, 35, 25 },完成计算后A = { 10, 20, 30 }。*/#include <iostream>using namespace s

2015-07-31 09:48:38 5514 1

原创 算法题:压缩任意字符串

//通过键盘输入一串任意字符串。//请编写一个字符串压缩程序,将字符串中连续出//席的重复字母进行压缩,并输出压缩后的字符串。/*如:输入AABBCC,输出2A2B2C;输入,,,..,输出3,2.。*/#include <iostream>#include <string.h>#include <stdlib.h>using namespace std;void Grial(ch

2015-07-31 01:02:30 1327 2

原创 算法题:给你一个自然数N,求[6, N]之内的所有素数中, 两两之和为偶数的那些偶数。

/*算法题:给你一个自然数N,求[6, N]之内的所有素数中,两两之和为偶数的那些偶数。*/#include <iostream>using namespace std;void Grial(int n){ int *b = new int[n]; int k = 0; b[k++] = 2; b[k++] = 3; b[k++] = 5;

2015-07-31 00:25:56 1893 3

原创 100对黑白球问题的多种思路

《编程之美》的概率题:一个桶里面有白球、黑球各100个,现在按下述规则取球: i 、每次从通里面拿出来两个球; ii、如果取出的是两个同色的球,就再放入一个黑球; ii、如果取出的是两个异色的球,就再放入一个白球。问:最后桶里面只剩下一个黑球的概率是多少?第一种方案(只关注一种球的变化): i.如果取出的是两个白球,白球减少2个。 ii.如果取出的是两个黑球

2015-07-30 23:09:14 2074

原创 C++深度理解复杂链表的构造复制

#include <iostream>using namespace std;#define Default -1struct Node{ int data; Node *next; Node *other;//这是复杂链表的额外的一个指针,指向一个指定位置的节点。 Node(int d = int()) :data(d), next(NULL), other

2015-07-30 19:35:46 1187

原创 纯c结构体与c++结构体的理解

//main.c//如果文件名是以.cpp结尾的说明这是一个c++的源程序,//在c++的源程序中,class的作用与struct的作用一模一样,//除了他们默认的成员属性不一样除外(class 默认是私有的,//struct默认是共有的),同样struct有this指针,同样struct//可以继承,同样struct也支持c++多态的所有属性,同样struct//有虚表,下面就是我做的一

2015-07-29 09:39:04 989 2

原创 ncurses简单的一个多窗口程序

#include <ncurses.h>#include <string.h>#include <iostream>#include <stdlib.h>using namespace std;void* head_refresh(void *arg);void* input_refresh(void *arg);void* output_refresh(void *arg);void

2015-07-27 23:47:53 3232 1

原创 windows和linux中UDP编程

//servser.cpp#include <iostream>#include <windows.h>#include <stdio.h>#include <string.h>#define IP "127.0.0.1"#define PORT 8888#pragma comment(lib,"ws2_32.lib")using namespace std;char* GetTime

2015-07-27 11:20:09 672

原创 void (*Pfun(int, void(*Qfun)(int))) (int)

#include <iostream>using namespace std;typedef void(*PF)(int);void fun(int a){ cout << "这里是参数是整形的函数fun(int)" << endl;}void Printf(int a){ cout << "这里是参数是整形的函数Printf(int)" << endl;}void(

2015-07-27 02:47:09 1497 1

原创 windows和linux的tcp套接字编程

windows下面的代码如下面//Server.cpp#include <iostream>#include <windows.h>#define IP "127.0.0.1"#define PORT 8888#pragma comment(lib,"ws2_32.lib")using namespace std;char* GetTime();int main(){ WSA

2015-07-26 21:35:08 1208

原创 strtok()分割字符串函数

#include <iostream>#include <string.h>using namespace std;char *my_strtok(char *dist,const char *src){ static char *result; //此处使用静态变量保存dist, //为了满足库函数strtok(NULL," ")的实现。 char map[

2015-07-22 01:20:42 981

原创 C++哈希表

#include <iostream>#include <string.h>#define MAX 13using namespace std;template<typename Type>struct Node{ Type *data; Node *next; Node(const Type *str = "") :data(new Type[strlen(str

2015-07-21 01:24:35 681

原创 C++求解数组中出现超1/4的三个数字。

#include <iostream>using namespace std;//求x!中k因数的个数。int Grial(int x,int k){ int Ret = 0; while (x) { Ret += x / k; x /= k; } return Ret;}int main(){ cout

2015-07-20 16:45:42 1116

原创 C++简单版BitSet求解大量数据是否存在莫个数

#include <iostream>using namespace std;template<int N>class BitSet{public: BitSet() { set(); } void set() { for (int i = 0; i < Nm; i++) { v

2015-07-20 16:11:22 835

原创 C++快速排序总结

#include <iostream>#include <stack>using namespace std;//快速排序的非递归版本。void Swap(int &a, int &b){ int temp = a; a = b; b = temp;}int Sort(int a[],int low,int high){ int i = low;

2015-07-19 20:59:38 477

原创 C++归并排序总结

#include <iostream>using namespace std;//归并排序非递归版。void Sort(int a[], int n,int high){ int k; for (int i = 0; i < high; i += 2 * n) { int x = i;//001 int y = i + n;//2 2

2015-07-19 20:52:23 727

原创 C++二叉树笔试题

#include <iostream>#include <stack>#include <queue>using namespace std;template<typename Type>struct Node{ Node* right; Node* left; Type data; Node(Type tp = Type()) :data(tp),righ

2015-07-17 15:23:17 1118

原创 C++链表冒泡,归并,插入排序(纯指针)

#include <iostream>using namespace std;//别问我为什么要写链表的冒泡排序。struct Node{ int data; Node *next; Node(int d = int()) :data(d), next(NULL){}};class List{public: List(int a[], int n)

2015-07-16 14:30:52 1343

原创 C++链表冒泡排序

#include <iostream>using namespace std;//别问我为什么要写链表的冒泡排序,操蛋操蛋操蛋。struct Node{ int data; Node *next; Node(int d = int()) :data(d), next(NULL){}};class List{public: List(int a[], i

2015-07-15 21:23:18 2394

原创 C++求解最大子矩阵之和

#include <iostream>using namespace std;//求最大子矩阵的和。//将多维数组想象成一维数组求最大的子序列和来计算。int Grial(int n,int a[]){ int i = 0; int count; int max; for (; i < n; i++) { if (i == 0)

2015-07-14 16:04:18 3843

原创 C++单链表递归逆序

#include <iostream>using namespace std;struct Node{ int data; Node *next; Node(int d = int()) :data(d), next(NULL){}};class List{public: List() { first = NULL; }

2015-07-14 13:45:51 1310

原创 SOCKET编程

server.cpp#include <iostream>#include <string.h>#include <windows.h>#define PORT 5000using namespace std;#pragma comment(lib,"ws2_32.lib")DWORD WINAPI RecvSendMessage(LPVOID arg){ char serbuf

2015-07-12 21:32:07 533

原创 C++腾讯笔试题

#include <iostream>using namespace std;//产生任意范围的随机数。int Grial(int i,int j ){ int x = 0; while (!(x>=i && x<j)) { x = rand() % j; } return x;}int main(){ cout <<

2015-07-12 12:02:19 1075

原创 C++再论单例模式

#include <iostream>#include <windows.h>#include <mutex>std::mutex gmutex;using namespace std;template<typename Type>class Singleton{public: static Type* GetSingleton() { if (s

2015-07-11 15:45:52 724

原创 C++再次理解虚表

#include <iostream>using namespace std;class Base{public: virtual void fun1() { cout << "Base::fun1()" << endl; } virtual void fun2() { cout << "Base::fun2()" <<

2015-07-11 13:40:09 722

原创 C++智能指针大总结

//最挫的智能指针。#include<iostream>using namespace std;template<typename Type>class my_auto_ptr{public: my_auto_ptr(Type* p = NULL) :ptr(p){} my_auto_ptr(const my_auto_ptr& ma) { ptr

2015-07-11 10:49:20 785

原创 C++笔试题经典的两个

//实现一个自己版本的string。#include <iostream>#include <string.h>using namespace std;class String{public: String(const char *s = "") { str = new char[strlen(s) + 1]; copy(str,s);

2015-07-10 14:46:59 680 1

原创 C++两道笔试题

//现给定一个含有n个元素的数组,请随机获取其中的m个元素(不能重复获取)。#include <iostream>#include <stdlib.h>using namespace std;void Grial(int a[], int n,int x){ int *b = new int[x]; int k = 0; int i = n; while (x

2015-07-10 13:45:24 717

原创 C++关键字大总结

register: 如果有一些变量使用频繁,则为存取变量的值少花一些时间,可以将该局部变量的值放在CPU的寄存器中,需要时直接从寄存器中取出参加运算,不必去内存中去存取。由于寄存器的存取速度远远高于内存的存取速度,因此这样做可以提高执行效率。这种变量叫做“寄存器变量”,用register做声明。说明: (1)只有局部自动变量和形式参数可以作为寄存器变量,其他

2015-07-09 15:31:15 938

原创 C++面试题一大波

//打印1到最大的n位数。//题目:输入数字n,按顺序打印出从1到最大的n位十进制数。比如://输入3,则打印出1、2、3一直到最大的3位数999.//[陷阱]:这个题目很容易想到的办法就是先求出最大的数。然后循环输出就可以了。#include <iostream>#include <string.h>using namespace std;void Grial(char *str,

2015-07-09 15:27:39 788

原创 C++字典树

#include <iostream>#include <vector>#define _MAX_ 256using namespace std;struct Node{ Node *next[_MAX_]; int count[_MAX_];//计数,看这个字符出现的次数。 Node() { int i=0; for (; i

2015-07-09 09:14:56 1154

原创 Bridge桥接模式

#include <iostream>using namespace std;//Bridge桥接模式。class Base{public: virtual void Printf()=0;};class Son1 :public Base{public: void Printf() { cout << "Son1::Printf()" <<

2015-07-07 09:38:05 706

原创 Memento记忆模式

//Memento记忆模式。#include <iostream>#include <string.h>using namespace std;class Memento;class Originator{public: Originator(char *s = "") { _str = new char[100]; strcpy(_st

2015-07-06 21:28:12 695

原创 Observer观察者模式

#include <iostream>#include <string.h>#include <vector>using namespace std;//观察者模式。//定义了一对多的关系,让多个观察对象同时监听一个主题对象,//当主题对象发生变化时,多个对象作出相应的响应。class School{public: School(char *s) {

2015-07-06 20:57:30 591

原创 C++笔试题第三波

#include <iostream>using namespace std;static int gflags = 0;//杨氏矩阵的查找。int FindVal(int (*a)[8],int x,int y,int val){ int i = 0; int j = y - 1; while (i <= 5 && j >= 0) { if

2015-07-06 14:59:48 626

原创 State状态机模式

#include <iostream>using namespace std;class Contex;//即使此处声明了,如果类中调用的有Contex函数,//那么编译器也会找不到定义的地方,所有这里我将//所有的类的实现都延迟在外面,这样对于每一个类而言,//其他的类都是可见的,最大的好处就是类之间的相互调用//不会产生什么未定义类型的错误警告。class Base{publi

2015-07-05 09:22:40 911

原创 C++atoi与atof

#include <iostream>using namespace std;static int sflags = 0;//atof的函数实现。bool Isnum(char ch){ return (ch - '0') >= 0 || (ch - '0') <= 9;}float Getnum(char *s,int flags){ float count = 0

2015-07-04 15:10:23 1165

原创 C++字符串操作笔试题第二波

//1.字符串替换空格:请实现一个函数,把字符串中的每个空格替换成“%20”。//例如输入“we are happy.”,则输出“we%20are%20happy.”。#include <iostream>#include <assert.h>#include <string.h>using namespace std;char* Grial(char *s){ assert(s

2015-07-03 16:27:53 2196 1

空空如也

空空如也

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

TA关注的人

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