poj2752—Seek the Name, Seek the Fame
来源:互联网 发布:ipo 净利润 数据 编辑:程序博客网 时间:2024/06/03 17:37
传送门:点我
The input contains a number of test cases. Each test case occupies a single line that contains the string S described above.
Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.
Restrictions: Only lowercase letters may appear in the input. 1 <= Length of S <= 400000.
For each test case, output a single line with integer numbers in increasing order, denoting the possible length of the new baby's name.
ababcababababcababaaaaa
2 4 9 181 2 3 4 5
题意:给定一个字符串s,从小到大输出s中既是前缀又是后缀的子串的长度。
贴代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<stack>using namespace std;#define N 400006char s[N];int Next[N];void make_Next(int n){ int i,j; for(i=1,j=0; i<n; i++) { while(j>0&&s[i]!=s[j]) j=Next[j-1]; if(s[i]==s[j]) j++; Next[i]=j; }}int main(){ int t,j; cin>>t; while(~scanf("%s",s)) { int len=strlen(s); Next[0]=0; make_Next(len); stack<int> sta; j=len-1; while(Next[j]!=0) { sta.push(Next[j]); j=Next[j-1]; } while(!sta.empty()) { printf("%d ",sta.top()); sta.pop(); } printf("%d\n",len); } return 0;}
阅读全文
0 0
- POJ2752 Seek the Name, Seek the Fame
- POJ2752:Seek the Name, Seek the Fame
- poj2752 Seek the Name, Seek the Fame
- POJ2752 Seek the Name, Seek the Fame
- poj2752 seek the name seek the fame
- poj2752 Seek the Name, Seek the Fame
- POJ2752 Seek the Name, Seek the Fame
- poj2752-Seek the Name, Seek the Fame
- poj2752 Seek the Name,Seek the Fame
- POJ2752 Seek the Name, Seek the Fame
- poj2752 seek the name,seek the fame
- POJ2752 Seek the Name, Seek the Fame
- POJ2752 Seek the Name, Seek the Fame
- poj2752 Seek the Name, Seek the Fame
- POJ2752-Seek the Name, Seek the Fame
- [POJ2752] Seek the Name,Seek the Fame
- POJ2752 Seek the Name, Seek the Fame
- 【POJ2752】seek the name,seek the fame
- 5.AWK细节操作转载
- com.fasterxml.jackson.databind.exc.MismatchedInputException
- Hadoop运行任务时一直卡在: INFO mapreduce.Job: Running job
- 剑指offer(10)—矩形覆盖
- 2D单应的归一化DLT
- poj2752—Seek the Name, Seek the Fame
- HTTP缓存机制及原理
- linux内核中断-数据结构-关系图解
- 决策树
- c++ 写注册表让程序开机自启动
- java使用tomcat&&原生ajax
- golang--net/rpc
- (1).hdfs特性及适用场景
- 【数位DP】HDU6148[Valley Number]题解