poj2752
来源:互联网 发布:淘宝客推广计划怎么写 编辑:程序博客网 时间:2024/05/22 18:03
发现不优化的next数组经常用啊……
#include<iostream>#include <string.h>#include <stdio.h>#include <stack>using namespace std;int next[1000010];char p[1000010];int pLen;void GetNext(){ pLen = strlen(p); next[0] = -1; int k = -1; int j = 0; while (j < pLen) { //p[k]表示前缀,p[j]表示后缀 if (k == -1 || p[j] == p[k]) { ++j; ++k; next[j] = k; } else { k = next[k]; } }}stack<int> s;int main(){ while(~scanf("%s",p)&&strcmp(p,".")!=0) { GetNext(); // cout<<pLen; while(next[pLen]!=-1) { //cout<<pLen; s.push(pLen); pLen=next[pLen]; } // return 0; printf("%d",s.top());s.pop(); while(!s.empty()) { printf(" %d",s.top()); s.pop(); } printf("\n"); } return 0;}
阅读全文
0 0
- poj2752
- poj2752
- POJ2752
- poj2752
- POJ2752
- poj2752
- poj2752
- poj2752 kmp
- poj2752---KMP
- poj2752(KMP)
- poj2752 KMP
- POJ2752(KMP)
- poj2752 Milking Grid--------KMP
- poj2752 kmp 进一步运用
- 模式匹配KMP POJ2752
- POJ2752 C代码
- KMP 专场 POJ2752
- poj2752 kmp 模板题
- gitbook安装与使用
- PhantomJS快速入门
- 带你重拾概率论
- 两种单例模式
- leetcode 435. Non-overlapping Intervals 消除覆盖区间
- poj2752
- 蓝桥杯算法训练 字符串变换 java
- OkHttp二次封装类
- HDU
- WebService生成客户端代码
- 1、MyBatis入门
- No bean named systemService is defined(Springmvc)报错一种解决思路
- 浅谈task_struct结构
- Java程序异常 open cussors查询 ORA-01000: maximum open cursors exceeded ORA-06512: at "××××××", line ×× 通