HUST 1010 字符串匹配(最小循环节问题)
来源:互联网 发布:网络诈骗图片大全 编辑:程序博客网 时间:2024/06/05 23:58
There is a string A. The length of A is less than 1,000,000. I rewrite it again and again. Then I got a new string: AAAAAA...... Now I cut it from two different position and get a new string B. Then, give you the string B, can you tell me the length of the shortest possible string A. For example, A="abcdefg". I got abcd efgabcdefgabcdefgabcdefg.... Then I cut the red part: efgabcdefgabcde as string B. From B, you should find out the shortest A.
Input
Multiply Test Cases. For each line there is a string B which contains only lowercase and uppercase charactors. The length of B is no more than 1,000,000.
Output
For each line, output an integer, as described above.
Sample Input
bcabcab
efgabcdefgabcde
Sample Output
3
Input
Multiply Test Cases. For each line there is a string B which contains only lowercase and uppercase charactors. The length of B is no more than 1,000,000.
Output
For each line, output an integer, as described above.
Sample Input
bcabcab
efgabcdefgabcde
Sample Output
3
7
#include <cstdio>#include <cstring>#include <iostream>using namespace std;char array[1000005];int Next[1000005];int len;void GetNext(){int i=0,j=-1;Next[0]=-1;while(i<len){while(j>-1&&array[i]!=array[j])j=Next[j];Next[++i]=++j;}return;}int main(){while(scanf("%s",array)!=EOF){len=strlen(array);GetNext();printf("%d\n",len-Next[len]);}return 0;}此题注意观察
1 0
- HUST 1010 字符串匹配(最小循环节问题)
- hust 1010 最小循环节
- KMP + 求最小循环节 --- HUST 1010
- HDU 3746 字符串匹配(字符串的最小循环节问题)
- POJ 2406 (字符串的匹配) 最小循环节问题
- hust 1010 KMP算法求最小循环节
- HUST 1010 The Minimum Length(最小循环节)
- hust 1010 The Minimum Length(KMP求最小循环节)
- HUST 1010 The Minimum Length (kmp求最小循环节)
- hust 1010 最短循环节
- HUST 1010 KMP最短循环节
- hust 1010 minimum length 循环节
- POJ2406 字符串最小循环节
- 最小表示法 字符串循环同构问题
- HUST - 1010 The Minimum Length(KMP 循环节)
- hust 1010 - The Minimum Length KMP求循环节
- 【字符串】【KMP模板--最小循环节总结】
- hust 1017 Exact cover 最小覆盖问题 dancing links
- 开发者工具中js代码不能自动同步
- 对于一个频繁使用的短小函数,在C语言中应用什么实现,在C++中应用什么实现?
- Android Studio中如何使用Git和GitHub详解【图文】(二)
- 2.交换机元素 OpenFlow1.5核心概念翻译与理解-OpenFlow1.5中文版
- 贪心法部分背包问题的实现
- HUST 1010 字符串匹配(最小循环节问题)
- Populating Next Right Pointers in Each Node ---LeetCode
- 应用被强杀了怎么办
- 地图显示周边信息
- leetcode--- Kth Largest Element in an Array---快排
- 3.词汇表 OpenFlow1.5核心概念翻译与理解-OpenFlow1.5中文版
- 【第一章】 Spring概述 ——跟我学Spring3
- 使用mplayer将批量图片生成压缩视频
- ERROR ITMS-90168 错误处理