SDUT 1465 common factor

Source: Internet
Author: User

Common factor Time Limit: 1000 MS Memory limit: 65536K Title Description assume that a string also has a factor. A string is s1 and can then be represented by n strings s2, s2 is the factor of s1. For example, "ac" is a factor of "acac. Give two strings and find the public factor of them. Input Multiple groups of data, given two strings, s1, s2. It cannot exceed 100000 characters in length and does not contain spaces. Output one row of data in each group, with the public factor. Input acacacaaaaa sample output 11 Prompt calculate the common factor of length [cpp] # include <stdio. h> # include <string. h> # include <math. h> int a [1000000], B [1000000]; char s1 [1000000], s2 [1000000], s3 [1000000]; int main () {int I, j, n, m, s, t, l1, l2, top, top1, x; while (scanf ("% s", s1, s2 )! = EOF) {l1 = strlen (s1); s = 0; for (I = 1, top = 0; I <= l1; I ++) {if (l1% I = 0) {a [top ++] = I ;}} for (I = 0, top1 = 0; I <= top-1; I ++) {for (j = 0; j <= a [I]-1; j ++) {s3 [j] = s1 [j];} if (a [I] = l1) {B [top1 ++] = a [I]; continue;} for (j = a [I]; j <= l1-1; j + = a [I]) {for (x = 0; x <= a [I]-1; x ++) {if (s3 [x]! = S1 [j + x]) {break;} if (x! = A [I]) {break;} if (j = l1) {B [top1 ++] = a [I] ;}} l2 = strlen (s2 ); for (I = 0; I <= top1-1; I ++) {if (l2% B [I] = 0) {for (j = 0; j <= l2-1; j + = B [I]) {for (x = 0; x <= B [I]-1; x ++) {if (s1 [x]! = S2 [j + x]) {break;} if (x! = B [I]) {break ;}} if (j = l2) {s ++ ;}} printf ("% d \ n", s );} return 0 ;}

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.