字符串类操作
文章平均质量分 61
普通网友
这个作者很懒,什么都没留下…
展开
-
poj 字符串移位包含问题
字符串移位包含问题: 这道题是标准的KMP模板题 题意是给两个字符串 一个串通过位移是否能包含另一个串, 这里有个隐含条件,不一定只是A包含B,应该是A与B长的去包含短的, 比如有 ABCDE CDEABABAB 这两串应该是B串包含A串, 隐含条件找到了,那么怎么判断是否能通过移位包含呢? 一般想法是朴素字符串匹配的方法 从a[0]一直判断到a[size],也就是最后一位,如果搜原创 2012-10-05 16:06:11 · 565 阅读 · 0 评论 -
第一个出现且只出现一次的字符(递归 不能使用库函数以及for while)
#include using namespace std; char temp='#'; void FirstChar(char* pStr,int fir,int pos) { int len=strlen(pStr); if(pos >= len) return; cout<<fir<<" "<<pos<<" "<<pStr[fir]<<" "<<pStr[pos]<<endl;原创 2014-05-15 17:13:32 · 493 阅读 · 3 评论 -
10115 Automatic Editing
/* Rule Find Replace-by 1. ban bab 2. baba be 3. ana any 4. ba b hind the g Replace the first occurrence of the find string within the text by the replace-by string, then try to perform the sam原创 2013-11-14 13:41:29 · 482 阅读 · 0 评论 -
10361 - Automatic Poetry
/*题目大意: 给一对字符串 按原样输出除了''的第一行字符串 输出第二行时,交换两个<>的内容*/ #include #include #include /*第一个问题是把字符串的''去掉,然后原样输出*/ void toPoetry(const char szStr1[],const char szStr2[]) { //char* iPos = strchr(szS原创 2013-11-06 22:09:59 · 469 阅读 · 0 评论 -
Palindromes
/* 错了好几次,原因是忘了考虑单个字符的情况,还有就是当长度为奇数时 最中间的那个影响很大 */ #include #include #include char szChChReverse[26] = {'A',32,32,32,'3', 32,32,'H','I','L', 32,'J','M',32,'O', 32,32,32,'2原创 2013-11-05 23:22:11 · 459 阅读 · 0 评论 -
原样输出最长回文子串
#include #include #include #define MAXSIZE 5000 /*void Paliandrome(char*); int main() { char lpStr[] = "aaaMadam,I'm Adamzsd"; printf("源字符串: %s\n",lpStr); Paliandrome(lpStr); return 0; } void原创 2013-11-03 22:07:15 · 543 阅读 · 0 评论 -
KMP Next 再次详解
#include using namespace std; void Next(char str[],int next[]) { int i = 0; int j = -1; next[0] = -1; int len = strlen(str); while(i < len-1)//这里要注意i<len-1 的原因 { /* 设置next值分两种情况: 1原创 2013-11-01 15:28:49 · 590 阅读 · 0 评论 -
字符串翻转
/*把字符串前面的若干个字符移动到字符串的尾部。 如把字符串abcdef左旋转2位得到字符串cdefab。 请实现字符串左旋转的函数,要求对长度为n的字符串操作的时间复杂度为O(n), 空间复杂度为O(1)。*/ #include using namespace std; //第一种 void Function1(char str[],int len,int k); //第二原创 2013-10-16 16:39:00 · 520 阅读 · 0 评论 -
kmp算法
主要思想:当主串第i个字符与模式串第j个字符匹配 不等是不需要回朔i指针,而是利用已经得到的 部分匹配结果next数组,将模式串向右滑动 核心:当主串中第i个字符与模式串第j个字符匹配失败时, 主串中第i个字符(i不回朔)应与模式串中哪个字符匹配?? 这就要构建一个next数组,来存放当匹配失败应该在匹配的位置编号 怎么定原创 2012-06-04 21:16:40 · 341 阅读 · 0 评论 -
KMP 算法 字符匹配
#include using namespace std; void Next(char* s,int* next,int len) { /* 获得next数组其实相当于自身与自身做匹配。 初始i=0,j=-1;next[0]=-1; 在while中,if(j==-1 || s[i] = s[j]) 当j=-1 1.第一次进入循环,j++,i++ 做s[0]与原创 2014-05-20 17:01:07 · 421 阅读 · 0 评论