首页 > 学院 > 开发设计 > 正文

hdu 1358

2019-11-08 02:41:13
字体:
来源:转载
供稿:网友
#include <string.h>  #include <iostream>  #include <stdio.h>    char str[1000005];  int next[1000005];    void getnext()  {      int i = 0,j = -1;      memset(next,0,sizeof(next));      next[0] = -1;      while (str[i])      {          if(j == -1 || str[i] == str[j])          {              i++;              j++;              next[i] = j;          }          else          j = next[j];      }  }    void kmp()  {      int i,t;      for(i = 2;str[i-1];i++)      {          t = i-next[i];          if(i%t == 0 && i/t>1)          PRintf("%d %d/n",i,i/t);      }  }    int main()  {      int n,cnt = 1;        while(scanf("%d",&n)!=EOF && n)      {          scanf("%s",str);          printf("Test case #%d/n",cnt++);          getnext();          kmp();          putchar(10);      }        return 0;  }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表