POJ2752 Seek the Name, Seek the Fame
来源:互联网 发布:stp 查看环路端口 编辑:程序博客网 时间:2024/05/16 07:48
KMP问题中的get_next()应用,详情请参阅算法导论相关章节
/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2012-03-14 20:19 # Filename: POJ2752 Seek the Name, Seek the Fame.cpp # Description : ******************************************************************************/#ifdef _MSC_VER#define DEBUG#define _CRT_SECURE_NO_DEPRECATE#endif#include <fstream>#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <limits.h>#include <algorithm>#include <math.h>#include <numeric>#include <functional>#include <ctype.h>#define MAX 400010using namespace std;char str[MAX];int ans[MAX],next[MAX];void get_next(){ int i = 0, j = -1 , len=strlen(str); next[0] = -1; while(i < len){ if(j == -1 || str[i] == str[j]){ i ++; j ++; next[i] = j; } else j = next[j]; }}int main(void){#ifdef DEBUG freopen("../stdin.txt","r",stdin); freopen("../stdout.txt","w",stdout); #endif while(gets(str)) { int cnt=0; int len=strlen(str); get_next(); for(int i=len;i>=0;) { ans[cnt++]=i; i=next[i]; } for(int i=cnt-2;i>=0;--i) printf("%d%c",ans[i],(i==0)?'\n':' '); } return 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
- 电能质量监测装置人机界面的实现
- sasa
- Ext.data.Store动态修改url
- __stdcall约定
- 一分钟制作U盘版BT3 - 有图滴儿 bt3破解教程
- POJ2752 Seek the Name, Seek the Fame
- 多目运算符
- ZOJ 1084 Channel Allocation
- 一些网址
- MFC获取文档属性
- 直接在包中创建用例
- 电能质量监测装置界面实例
- eclipse package,source folder,folder区别及相互转换
- sql plus操作oracel(windows平台)基础之简易新手篇