poj 2406 求字符串中重复子串的个数
Sample Input
abcd
aaaa
ababab
.
Sample Output
1 //1个abcd
4 //4个a
3 //3个ab
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std; const int MAXN=;
char T[MAXN];
int next[MAXN];
int n;
void getNext()
{
int j,k;
j=;
k=-;
next[]=-;
while(j < n)
{
if(k==-||T[j]==T[k])
{
j++;
k++; next[j]=k;
}
else k=next[k]; }
if(n%(n-k)==)
printf("%d\n",n/(n-k));
else
printf("1\n") ;
}
int main()
{ while(scanf("%s",&T) != EOF)
{
if (T[]=='.')
break ;
n = strlen(T) ;
getNext(); }
return ;
}
poj 2406 求字符串中重复子串的个数的更多相关文章
- poj 1961 (求字符串中的重复子串)
Sample Input 3aaa12aabaabaabaab0Sample Output Test case #12 23 3 Test case #22 2 //aa有2个a6 2 //aabaa ...
- spoj 694 求一个字符串中不同子串的个数
SPOJ Problem Set (classical) 694. Distinct Substrings Problem code: DISUBSTR Given a string, we need ...
- JS-取出字符串中重复次数最多的字符并输出
/** 取出字符串中重复字数最多的字符 */ var words = 'sdfghjkfastgbyhnvdstyaujskgfdfhlaa'; //创建字符串 var word, //单个字符 le ...
- PAT 字符串-02 删除字符串中的子串
/* 2 *PAT 字符串-02 删除字符串中的子串 3 *2015-08-09 4 作者:flx413 5 */ #include<stdio.h> #include<string ...
- 《Python CookBook2》 第一章 文本 - 替换字符串中的子串
替换字符串中的子串 任务: 给定一个字符串,通过查询一个字符串替换字典,将字符串中被标记的子字符串替换掉. 解决方案: >>> import string >>> ...
- Python2.7.3移除字符串中重复字符(一)
移除重复字符很简单,这里是最笨,也是最简单的一种.问题关键是理解排序的意义: # coding=utf-8 #learning at jeapedu in 2013/10/26 #移除给定字符串中重复 ...
- javascript 去除字符串中重复字符
/** * 去除字符串中重复的字符,以下提供2种方法, * removeRepeat()为自己所想: * removeRepeat2()参考网上思路补充的 * removeRepeat3()敬请期待· ...
- C++ 在字符串中插入子串+推断字符串是否由空格组成
// Example3.cpp : 定义控制台应用程序的入口点. #include "StdAfx.h" #include <string> #include < ...
- jst通用删除数组中重复的值和删除字符串中重复的字符
以下内容属于个人原创,转载请注明出处,非常感谢! 删除数组中重复的值或者删除字符串重复的字符,是我们前端开发人员碰到很多这样的场景.还有求职者在被面试时也会碰到这样的问题!比如:问删除字符串重复的字符 ...
随机推荐
- JAVA记录-Servlet介绍
1.什么是Servlet Servlet是sun公司提供的一门用于开发动态web资源的技术.Sun公司在其API中提供了一个servlet接口,用户若想用发一个动态web资源(即开发一个Java程序向 ...
- logback异步输出日志(生产者消费者模型),并非批量写入日志。
一直对logback异步输出日志误解为异步批量写入日志. 今天看了源代码. 首先logback的异步日志是如何配置的: <!-- 管理端用户行为日志异步输出,异步的log片段必须在同步段后面,否 ...
- 解决idea中找不到程序包和找不到符号的问题
问题如图: 解决方法: 将三处编码都设置成UTF-8,亲测有效 本人也是拜读大佬博客后解决的: http://www.cnblogs.com/wzhanke/p/4747966.html
- Postfix - Extmail 邮箱系统
Postfix Dovecot Extmail 邮箱系统早前的内部邮箱系统重新整理下:现在Extmail官方有集成镜像的EMOS_1.6_x86_64免费版:可直接下载安装: 系统环境: linux ...
- mysql 查询优化案例汇总
一 简介:此文章为经历过的sql案例集合和相关思路 二 案例1: 现象: 测试环境出现select语句,join2张表多次join,explain结果如下 出现 using where,using j ...
- python - getattr 与 getattribute 机制
#__getattribute__ class Foo(): def __init__(self,name): self.name = name def __getattr__(self, item) ...
- HTML中Meta标签中http-equiv属性
HTML中Meta标签中http-equiv的用法: <meta http-equiv="这里是参数" content="这里是参数值"> 1.Ex ...
- js遍历对象的方法
1. for ... in 语句 for (let variable in object) { ... } https://developer.mozilla.org/zh-CN/docs/Web/ ...
- VS Code中Matlab插件安装设置
Install the extension in VS Code Open the command palette using Ctrl+Shift+P Type ext install Matlab ...
- 同步sync 异步async
线程中 同步任务是串行队列,也就是按顺序执行. 同步任务:不会开辟新的线程,它是在当前线程执行的. dispatch 调度 GCD里面的函数都是以dispatch开头的. 同步任务 步骤: 1. ...