POJ
来源:互联网 发布:淘宝斗鱼 编辑:程序博客网 时间:2024/06/16 21:15
https://cn.vjudge.net/contest/189927#problem/C
题意:就是问你前后缀相等的长度,从小到大去输出。
思路:nex数组里面存的就是当前的相等的前后缀长度,最长的相等前后缀就是他自己,之后的想澄清前后缀就是nex[len],之后一直输出直到nex[len]为0 就好了上代码:
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char ch[400050];int nex[400050],ans[400050];void pre_kmp(){memset(nex , 0 ,sizeof(nex));int len = strlen(ch) , k = -1 ,i = 0;nex[0]=-1;while(i < len){if (k == -1 || ch[i] == ch[k]){i++;k++;nex[i]=k;}else k = nex[k];}}int main(){while(scanf("%s",ch)!=EOF){pre_kmp();int cnt = 0;int p = strlen (ch);while(p>=1){ans[cnt++]=p;p = nex[p];}for(int i = cnt -1 ;i >=0 ; i--){if(i == cnt-1){printf("%d",ans[i]);}else printf(" %d",ans[i]);}puts(""); }return 0;}
阅读全文
0 0
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- fopen文件打开模式
- 数据结构实验之链表八:Farey序列
- python中copy的使用
- Python 爬虫 爬取视频
- JavaScript大厦之JS运算符
- POJ
- 第八次作业
- IntelliJ IDEA 编译错误,提示 Compilation failed: internal java compiler error或java compiler failed
- ue4 的sequence的执行顺序
- Python语言下的机器学习库
- JavaScript正则表达式
- java第七天/10.15
- JAVA 循环语句作业
- Ionic中单选按钮radio的简单使用