超强悍的ac代码 PKU2406 百度搜的
2010-07-20 20:20
225 查看
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char str [1000010];
int next[1000010];
int getnext()
{
int i= 0, j= -1; next[0]= -1;
while( str[i] )
{
if( j== -1 || str[i]== str[j] )
{
++i,++j;
next[i]= j;
}
else j= next[j];
}
int len= strlen(str);
i= len- j;
if( len% i== 0 ) return len/ i;
else return 1;
}
int main()
{
while( gets( str), str[0]!= '.' )
printf("%d\n", getnext() );
return 0;
}
能看懂吗?哈哈。。。。。。
#include <stdlib.h>
#include <string.h>
char str [1000010];
int next[1000010];
int getnext()
{
int i= 0, j= -1; next[0]= -1;
while( str[i] )
{
if( j== -1 || str[i]== str[j] )
{
++i,++j;
next[i]= j;
}
else j= next[j];
}
int len= strlen(str);
i= len- j;
if( len% i== 0 ) return len/ i;
else return 1;
}
int main()
{
while( gets( str), str[0]!= '.' )
printf("%d\n", getnext() );
return 0;
}
能看懂吗?哈哈。。。。。。
相关文章推荐
- 我在pku AC的代码
- pku3414 POTS(哦也。。。。。。。。又输了。。这是第几次无耻发别人代码AC了。。。。。。我垃圾我笨我傻我真TMD不是东西!!!!
- 获取全国市以及地理坐标,各大坐标系北斗,百度,WGS-84坐标系的转换,有图,有代码
- 贴下百度博客自动加好友的简单代码示例!!(c#.net实现)
- 百度自动推送代码
- 百度搜狗神马搜索劫持 来源网站跳转 快照霸屏 竞价劫持 霸屏代码
- 在网页中放入百度、搜狗、搜搜 搜索代码搜索出现乱码解决办法
- 经典面试题(二)附答案 算法+数据结构+代码 微软Microsoft、谷歌Google、百度、腾讯
- Google和百度、雅虎的站内搜索代码
- 收藏 '分享 到百度、微信'功能代码
- Python使用百度API上传文件到百度网盘代码分享
- 2015 湘潭大学程序设计比赛(Internet) 全解析 + AC代码
- 百度手写板代码JavaScript远程调用的实现(鼠标输入法)
- Google和百度、雅虎的站内搜索代码
- AC自动机代码实现
- 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)
- 经典面试题(二)附答案 算法+数据结构+代码 微软Microsoft、谷歌Google、百度、腾讯
- 经典面试题(四)附答案 算法+数据结构+代码 微软Microsoft、谷歌Google、百度、腾讯
- 增强Eclipse ,MyEclipse 的代码提示功能(图文教程)V1.1(强悍推荐)
- Google和百度、雅虎的站内搜索代码