HDU 1358 Period

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1358

Explanation of output data,

Group 1:

2 2 indicates the first letter to the second letter, and a appears twice.

3 3 indicates the first letter to the third letter, and a appears three times.

Group 2:

2 2 indicates the first letter to the second letter, and a appears twice. 6 2 indicates the first letter to the sixth letter, and AAB appears twice. 9 3 indicates the first letter to the ninth letter, and AAB appears three times. 12 4 indicates the first letter to 12th letters, and AAB appears four times.
 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4  5 using namespace std; 6  7 int next[1000010]; 8 char str[1000010]; 9 10 void get_next()11 {12     int i=0,j=-1;13     next[0]=-1;14     int lens=strlen(str);15     while (i<lens)16     {17         if (j==-1||str[i]==str[j])18         {19             i++;20             j++;21             next[i]=j;22             if (i>=2&&j>=1)23             {24                 if (i%(i-next[i])==0)25                 {26                     int k=i/(i-next[i]);27                     printf ("%d %d\n",i,k);28                 }29             }30         }31         else32             j=next[j];33     }34 }35 int main ()36 {37     int n,flag=1;38     while (scanf("%d",&n),n)39     {40         getchar();41         scanf("%s",str);42         printf ("Test case #%d\n",flag++);43         get_next();44         printf ("\n");45         //lens=strlen(str);46     }47     return 0;48 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.