hoj1952 power string
2012-06-08 15:42
267 查看
/*This Code is Submitted by billforum for Problem 1952 at 2012-06-08 15:39:09*/ #include <stdio.h> #include <iostream> #include <fstream> #include <vector> #include <exception> #include <cstring> #include <stdlib.h> using namespace std; const int Len=1000000; int next[Len+5]; void getNext(int next[],char str[]) { int len=strlen(str); int i=0,j=-1; while(i<len) { if((j==-1)||(str[i]==str[j])) { j++; i++; next[i]=j; } else j=next[j]; } return; } void print(int next[],int len) { for(int i=0;i<len;i++) printf("%d ",next[i]); } int cmp(char s1[],char s2[]) { int i=0,j=0;//i->s1,j->s2 int len1=strlen(s1),len2=strlen(s2); int times=0; while(i<len1) { if((j==-1)||(s1[i]==s2[j])) { i++; j++; if(j>=len2) { j=0; times++; } } else j=next[j]; } return times; } int main(int argc, char **argv) { char str1[Len+5]; memset(next,0,sizeof(next)); next[0]=-1; while(scanf("%s",str1)==1) { if(strcmp(str1,".")==0) break; int len1=strlen(str1); str1[len1]='.'; str1[len1+1]='\0'; getNext(next,str1); len1=strlen(str1); //print(next,len1); //cout<<endl; if((len1-1)%(len1-1-next[len1-1])==0) printf("%d\n",(len1-1)/(len1-1-next[len1-1])); else printf("1\n"); } return 0; }
相关文章推荐
- hoj1952 power strings
- poj 2406 Power String (KMP)
- 【hoj】1196 Power Crisis( Joseph'problem 变型)、1441 Eeny Meeny Moo
- Power string(poj 2406)
- POJ 2406 Power String
- FOJ1011 Power String
- [HOJ]HIT's Powerstation
- 安装Informatica PowerCenter 8.1.1服务器端,配置License Key,Connect string和character data movement mode .
- JSP和Servlet连接数据库 登陆验证ResultSet.getString("power")空指针问题
- POJ 2406 Power String 最短循环子串 - KMP
- POJ 2406 Power String(KMP)
- POJ 2406 Power String 后缀数组
- 【坑爹卡时题】Poj 2406 Power String
- JSP和Servlet连接数据库 登陆验证ResultSet.getString("power")空指针问题
- POJ 2406 Power String(KMP)
- 由beautyispower的post - “比较StringBuilder string” 所做的测试
- Power up C++ with STL: Part II (string, set, map)
- POJ-2406 Power string
- poj 2406 power string(KMP)
- POJ-2406 Power string