自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 【c++】模拟实现boost库下的scoped_array

//模拟实现boost库下的scoped_array#include #include using namespace std;template class scoped_array{private: T * px; scoped_array(scoped_array const &); scoped_array& operator=(scoped_array const

2015-07-17 14:38:48 911

原创 【c++】模拟实现boost库里的scoped_ptr

//模拟实现boost下的scoped_ptr#include #include using namespace std;template class scoped_ptr{private: T * px; scoped_ptr(scoped_ptr const &); scoped_ptr& operator=(scoped_ptr const &); void

2015-07-17 11:28:10 833

原创 【关键字】一些关键字用法总结

Register       用register声明的变量称寄存器变量,在可能的情况下会直接存放在机器的寄存器中;      但对32位编译器不起作用,当global optimizations(全局优化)开的时候,它会做出选择是否放在自己的寄存器中;    不过其它与register关键字有关的其它符号都对32位编译器有效。Const     被con

2015-07-14 19:45:37 2012

原创 【c语言】统计一个数字在排序数组中出现的次数

// 题目:统计一个数字在排序数组中出现的次数。//  例如:排序数组{1,2,3,3,3,3,4,5}和数字3,由于3出现了4次,因此输出4有一种最简单的算法,遍历。但是有比它效率更高的先看遍历:#include #include int num_time(int *arr, int len, int a){ int i = 0;

2015-07-14 19:33:51 6425

原创 【c++】简单的string类的几个基本函数

// string的几个基本函数的实现#include #include #include using namespace std;class String{public: String() { _str = new char[1]; _str[0] = '\0'; } String(char *str) { assert(str != NULL); _

2015-07-11 14:28:46 820

原创 【c语言】输入一组整数,求出最大子序列的和

输入一组整数,求出最大子序列的和.例如:序列: - 2 11 - 4 13 - 5 - 2,则最大子序列和为20。序列: - 6 2 4 - 7 5 3 2 - 1 6 - 9 10 - 2,则最大子序列和为16遍历是一种方法:#include int Max_Son(int *p, int len){ int Max_Sum = 0; i

2015-07-08 16:40:13 5126 2

原创 【c语言】数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字

题目:数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}, 由于数组中数字2出现了5次,超过数组的长度的一半,因此输出2一种办法是先把数组排序,那么超过一半的元素一定是数组最中间的元素。第二种办法比较抽象,设一个变量保存当前值,设一个次数,当前值与下一个值进行比较,如果相等,次数加一,如

2015-07-08 09:58:56 3606

原创 【c语言】调整数组使奇数全部都位于偶数前面

// 调整数组使奇数全部都位于偶数前面// 输入一个整数数组,实现一个函数,来调整该数组中数字的顺序使得数组中所有的奇数位于数组的前半部分,// 所有偶数位于数组的后半部分。#include #include void johh(int *p, int len){ int *q = p + len - 1; int temp; assert(p != NULL); w

2015-07-08 09:30:51 1663 1

原创 【c语言】输入一个递增排序的数组的一个旋转,输出旋转数组中的最小元素

//旋转数组的最小数字//题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。//输入一个递增排序的数组的一个旋转,输出旋转数组中的最小元素。//例如:数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转,最小元素是1。#includeint min_equ(int *src, int left, int right){ int i = 0; int

2015-07-07 16:25:20 1300

原创 【c语言】第一个只出现一次的字符题目:在字符串中找出第一个只出现一次的字符

// 第一个只出现一次的字符题目:在字符串中找出第一个只出现一次的字符。// 如输入“abaccdeff”,则输出’b’。#include #include char find_one(char *str){ int a[256]; int len = strlen(str); int i = 0; memset(a, 0, sizeof(a)); for (i

2015-07-06 20:45:46 4408 1

原创 【c语言】二维数组中的查找,杨氏矩阵在一个二维数组中,每行都按照从左到右的递增的顺序排序,输入这样的一个数组和一个数,判断数组中是否包含这个数

// 二维数组中的查找,杨氏矩阵在一个二维数组中,每行都按照从左到右的递增的顺序排序。// 每列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个数组和一个数,判断数组中是否包含这个数#include #define col 4#define rol 4int yang(int(*p)[col], int num){ int i = 0; int j = col

2015-07-06 15:25:56 1946

原创 【c语言】模拟实现库函数的atof函数

// 模拟实现库函数的atof函数#include #include #include #include double my_atof(char const *p){ double ret = 0; int flag = 1; int count = 0; assert(p != NULL); while (isspace(*p)) { p++; } whil

2015-07-04 16:09:11 1311

原创 【c语言】 模拟实现库函数的atoi函数

// 模拟实现库函数的atoi函数#include #include #include #include int my_atoi(char const *p){ int ret = 0; int a = 0; int flag = 1; assert(p != NULL); while (isspace(*p)) { p++; } while (*p) {

2015-07-04 14:51:00 863

原创 【c语言】模拟库函数strstr

// 模拟库函数strstr#include #include const char* my_strstr(const char *parent, const char *child){ const char *pgo = parent; const char *cgo = child; const char *pgos = parent; assert(parent !=

2015-07-04 11:49:37 681

原创 【c语言】判断一个字符串是否为另外一个字符串旋转之后的字符串

// .判断一个字符串是否为另外一个字符串旋转之后的字符串。// 例如:给定s1 = AABCD和s2 = BCDAA,返回1,给定s1=abcd和s2=ACBD,返回0#include #include #include int rotate(char *p, char *q){ assert(p != NULL && q != NULL); strncat(p,p,st

2015-07-04 10:03:30 1546

原创 【c语言】字符串替换空格:请实现一个函数,把字符串中的每个空格替换成“%20”

// 字符串替换空格:请实现一个函数,把字符串中的每个空格替换成“%20”。// 例如输入“we are happy.”,则输出“we%20are%20happy.”#include #include char* replace(char* p){ char* ret = p; int num = 0; int oldlen = 0; int newlen = 0;

2015-07-04 09:59:40 3366

原创 【c语言】模拟实现strchr函数,功能:在一个字符串中查找一个字符第一次出现的位置,如果没有出现返回NULL

// 模拟实现strchr函数,功能:在一个字符串中查找一个字符第一次出现的位置,如果没有出现返回NULL#include #include char const* my_strchr(char const *p,char c){ assert(p != NULL); while (*p) { if (*p == c) return p; else p++;

2015-07-02 10:15:04 2681

原创 【c语言】编写程序,使字符串逆序,空间复杂度O(1)

// 编写程序,使字符串逆序,空间复杂度O(1)#include #include char* reverse(char *p){ assert(p != NULL); char temp; char* q = p; char* ret = p; while (*q) { q++; } q--; while (p < q) { temp = *p; *p

2015-07-02 10:12:32 1486

原创 【c语言】 模拟实现库函数strcat函数

// 模拟实现库函数strcat函数#include #include char* my_strcat(char *p, char const *q){ char *ret = p; assert(p != NULL); assert(q != NULL); while (*p) { p++; } while (*q) { *p = *q; p++;

2015-07-02 10:11:03 790

原创 【c语言】模拟实现库函数strcpy函数

// 模拟实现库函数strcpy函数#include #include char* my_strcpy(char const *p, char *q){ char *ret = q; assert(p != NULL); assert(q != NULL); while (*p) { *q = *p; p++; q++; } *q = '\0'; retu

2015-07-02 10:09:25 1838

原创 【c语言】实现一个函数,求字符串的长度,不允许创建第三方变量

// 实现一个函数,求字符串的长度,不允许创建第三方变量。#include #include int my_strlen_no(char const *p){ assert(p != NULL); if (*p == NULL) return 0; else return (1 + my_strlen_no(p + 1));}int main(){ char

2015-07-02 10:08:37 1166

原创 【c语言】实现一个函数,求字符串的长度

// 实现一个函数,求字符串的长度#include #include int my_strlen(char const *p){ int count = 0; assert(p != NULL); while(*p) { count++; p++; } return count;}int main(){ char *p = "zhaoyaqian"; p

2015-07-02 10:07:40 2717

原创 【c语言】不使用+-*/计算两个数的和

// 不使用+-*/计算两个数的和#include int add(int a, int b){ int c, d; do { c = a ^ b; d = (a & b) << 1; a = c; b = d; } while (b != 0); return a;}int ma

2015-07-01 14:13:06 1057

空空如也

空空如也

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

TA关注的人

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