Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一样的算法, 2406(141ms), 1961(tle), 就多个输出, 这么费时么, 我的算法应该是O(n)呀!求大神给看看!#include <cstdio> #include <cstring> #define N 1000001 char str[N], substr[N]; int main() { char *p, *strend; int len, ppos; int period, count; int test = 0; while(scanf("%d", &len), len != 0) { scanf("%s", str); printf("Test case #%d\n", ++test); ppos = 0; p = str; strend = str + len; while(p < strend) { period = p - str + 1; while(ppos < period) { substr[ppos] = str[ppos]; ++ppos; p = str + period; } substr[ppos] = '\0'; count = 1; while(strncmp(p, substr, period) == 0) { ++count; p += period; printf("%d %d\n", int(p - str), count); } } printf("\n"); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator