Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

一样暴力,不过我的204ms,stl虽然好用,但是效率不行啊!

Posted by sicojuy at 2011-04-23 23:40:05 on Problem 2406
In Reply To:用cin超时 改成scanf后ac 内存5956k 用时2938ms 没用算法 硬想的办法 附代码 Posted by:gjl87910lq at 2009-05-11 16:56:43
#include <stdio.h>
#include <string.h>
#define N 1000001

char str[N], substr[N];

int find_str(char s[], char subs[], int n)
{
	int i;
	for(i = 0; i < n; ++i)
		if(s[i] != subs[i])
			return 0;
	return 1;
}

int main()
{
    char *p;
    int len;
    int i, k;
    while(scanf("%s", str), strcmp(str, ".") != 0)
    {
        len = strlen(str);
        for(i = 0; i < len; ++i)
        {
            substr[i] = str[i];
	    k = i + 1;
	    substr[k] = '\0';       
            if(len % k == 0)
            {
                p = str + k;
                while(find_str(p, substr, k))
                    p += k;
                if(p == str + len)
                    break;
            }
        }
        printf("%d\n", len / k);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator