kuangbin专题十六 KMP&&扩展KMP POJ2406 Power Strings
Input
Output
Sample Input
abcd
aaaa
ababab
.
Sample Output
1
4
3
Hint
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
using namespace std;
int Next[],n;
char p[]; void prekmp() {
int i,j;
j=Next[]=-;
i=;
while(i<n) {
while(j!=-&&p[i]!=p[j]) j=Next[j];
if(p[++i]==p[++j]) Next[i]=Next[j];
else Next[i]=j;
}
} int main() {
//freopen("in","r",stdin);
while(~scanf("%s",p)) {
if(p[]=='.') break;
n=strlen(p);
prekmp();
int l=n-Next[n];
if(n%l==) printf("%d\n",n/l);
else printf("%d\n",);
}
}
kuangbin专题十六 KMP&&扩展KMP POJ2406 Power Strings的更多相关文章
- kuangbin专题十六 KMP&&扩展KMP HDU2609 How many (最小字符串表示法)
Give you n ( n < 10000) necklaces ,the length of necklace will not large than 100,tell me How man ...
- kuangbin专题十六 KMP&&扩展KMP HDU2328 Corporate Identity
Beside other services, ACM helps companies to clearly state their “corporate identity”, which includ ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- kuangbin专题十六 KMP&&扩展KMP HDU3336 Count the string
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...
- kuangbin专题十六 KMP&&扩展KMP POJ3080 Blue Jeans
The Genographic Project is a research partnership between IBM and The National Geographic Society th ...
- kuangbin专题十六 KMP&&扩展KMP HDU3746 Cyclic Nacklace
CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...
- kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条
一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...
- kuangbin专题十六 KMP&&扩展KMP HDU1686 Oulipo
The French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter 'e ...
- kuangbin专题十六 KMP&&扩展KMP HDU1711 Number Sequence
Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1], b[2], ...... , b[M] (1 <= M ...
随机推荐
- CreateThread demo
#include "stdafx.h"#include<windows.h>#include<strsafe.h>//win2003SDK必须安装 要不无此 ...
- 11-24网页基础--Js框架及学习思路
第一部分 基本语法: 1.数据类型(字符串.小数.整数.布尔.时间日期)var s="3.14" var n=parsefloat(s) s+=5;var s="abc3 ...
- python获得当前工作目录和修改
import os curDir = os.getcwd() 最近使用Python 写了很多脚本,想导入脚本,发现不知道如何查看python 的默认工作目录,并修改默认工作目录. 方法/步骤 查 ...
- Matlab并行编程方法1
相信很多朋友在利用matlab进行计算时,会遇到循环次数过大,或者是单次计算量过大的问题,比如需要计算的数值阵列数据量过大,利用传统的编程方式,跑一次程序几个小时,都要等的急死了是不是呢?如果遇到这种 ...
- Swing绘图API
----------------siwuxie095 工程名:TestSwingPaintAPI 包名:com.siwuxie095.swing ...
- SWT简介
--------------siwuxie095 SWT 简介: SWT(Standard Widget Toolkit) 也是基于一个对等体实 ...
- iOS 地图(添加大头针)
首先在工程中导入MapKit.framework库文件 #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <U ...
- Matlab 摄像机标定+畸变校正
博客转载自:http://blog.csdn.net/Loser__Wang/article/details/51811347 本文目的在于记录如何使用MATLAB做摄像机标定,并通过opencv进行 ...
- java线程安全的元素
集合类: Vector Stack HashTable enumeration 字符串: StringBuffer
- RobotFramework教程使用笔记——robotframwork中文乱码显示问题
转自:https://www.cnblogs.com/dreamyu/p/6878795.html 接口.数据库返回信息有中文的时候会显示unicode的样式,前面带个U这样的显示,如果我们想让它正常 ...