- 博客(10)
- 资源 (2)
- 收藏
- 关注
原创 Longest common substring(不连续子序列)
在前一篇文章中给出了最大连续子序列的实现本文主要是算法导论中的不连续的最大子序列算法的一种实现。输入:字符串str1和str2输出:最大不连续子序列以及子序列的长度 #include iostream>#includestring>using namespace std;templateclass T>inline T max(T a, T b)...{ return
2007-10-19 19:46:00
1021
原创 Longest common substring
我这里所说的longest common substring问题和算法导论中的不一样,主要是找出连续的最长子序列。输入:string S1,S2输出:所有连续的最长子序列 #include iostream>#includestring>using namespace std;void Pre_Process(string P, int* pi)...{ int m=P.
2007-10-19 17:02:00
1171
原创 关于字符串的匹配搜索问题
字符串匹配搜索最著名的当属KMP算法,今天花了一番功夫研究了一下该算法。算法的优点是时间复杂度和字符串的长度成线性关系,对于目标字符串T[n]和模式字符串P[m],算法需要的时间复杂度为O(m)的预处理和O(n)的匹配。具体的算法参见算法导论。利用KMP算法完成类似于strstr()的功能,打印一个字符串中所有以子串开头的组合。 #include iostream>#incl
2007-10-19 00:03:00
952
原创 字符串全排列问题
对于任意的输入字符串,输出其所有的排列情况,以及排列的总数 #includeiostream>using namespace std;int cnt=0;inline void swap(char&a, char& b)...{ char t=a; a=b; b=t;}void permutation(char a[], int m, int n) ...{ i
2007-10-12 14:30:00
1147
原创 求最大连续和问题
输入:数组a[n]输出:该数组中和最大的连续子序列,以及该最大和 int maxsub2(int* arr,int len)...{ int i,maxsum=INT_MIN,sum=0; int beg=0,end=0,pos=0; for(i=0;ilen;++i) ...{ sum+=arr[i]; if(s
2007-10-09 15:40:00
2071
2
原创 单链表的反向
给定单链表的头指针Head,可以将链表反向,一种方法利用指针直接赋值,一种借助stack先进后出的特性 #includeiostream>#includestack>using namespace std;struct node...{ int i; node* next;};void reverse1(node** head)...{ node* p1; no
2007-09-23 19:49:00
3045
原创 字符串中最大子串问题
输入一个字符串,输出其最大子串长度,即子串中任两个字符不相同 。本程序只能输入字母,空格以及逗号,并且不区分大小写,输出为第一个具有最大长度的子串以及其长度。 #includeiostream>#includestring>using namespace std;int chartoi(char c)...{ if(isalnum(c)) ...{
2007-09-23 13:14:00
1340
原创 螺旋矩阵
输入一个坐标值,输出其对应的数字void rotate1(int& x,int& y){ if(abs(x)==abs(y)) { if(x>=0&&y>=0) --x; else if(x>=0&&y ++y; else if(x ++x; else --y; } else if(abs(x)>abs(y)) { if(x>0)
2007-09-13 23:59:00
775
原创 Lvalues and Rvalues(转载)
C and C++ enforce subtle differences on the expressions to the left and right of the assignment operator If youve been programming in either C or C++ for a while, its likely that youve heard
2007-09-08 12:14:00
1685
原创 C++优化--按值返回和返回值优化
C++和C语言相比,最为人诟病的就是其性能问题,通常一条C语言经编译器解释后,可以固定转换成5—10条汇编语言,但是一条C++语言,就没有这么幸运了,可能会是3条汇编语言,也可能是300条。C++影响性能的原因很多,其中一个就是临时对象的创建和销毁。这里我简述一种减少创建临时对象的方法--返回值优化问题很多时候,函数需要按值返回,这其中就会不可避免地涉及到临时对象的创建和销毁。假设定义如下的C
2007-06-27 15:55:00
2462
Memory Management: Algorithms and Implementation in C/C++
2008-12-07
XML Schema
2008-10-30
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人