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 |
请教一下,偶的程序哪里写错了,总是TLE#include <stdio.h> #include <string.h> #include <ctype.h> char s[400001]; int n; int next[40001]; int nrec; int rec[40001]; main() { int x; char ch; // freopen( "e.in", "r", stdin ); // freopen( "e.out", "w", stdout ); while( (ch = getchar()) != EOF ) { if( !islower(ch) ) break; n = 0; do { s[n++] = ch; ch = getchar(); } while( islower(ch) ); x = 0; for( int i = 1; i < n; i++ ) { while( x && s[i] != s[x] ) x = next[x]; if( s[i] == s[x] ) x++; next[i] = x; } nrec = 0; for( x = n-1; x >= 0; x = next[x]-1 ) rec[nrec++] = x; for( int i = nrec-1; i >= 0; i-- ) printf( "%d ", rec[i]+1 ); printf( "\n" ); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator