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 |
原创算法,141ms#include <stdio.h> int a[1000001]; char s[1000001] = {0}; int main() { int m, i, c, j, x, t, k = 1; while( scanf( "%s", s ) && s[0] != 'E' ){ if( !s[1] ){ printf( "Case %d: 1\n", k ++ ); continue; } m = 1, c = 1, a[0] = 0; if( s[1] == s[0] ) m = 2; else a[1] = 1, c = 2; for( i = 2; s[i]; i ++ ){ for( j = 0, t = c - 1, c = 0; j < t; j ++ ){ if( -- a[j] >= 0 && s[a[j]] == s[i] ){ a[c ++] = a[j]; x = i - a[j] + 1; if( x > m ) m = x; } } if( s[i] == s[i - 1] ){ a[c ++] = a[t]; } else{ if( -- a[t] >= 0 && s[a[t]] == s[i] ){ a[c ++] = a[t]; x = i - a[t] + 1; if( x > m ) m = x; } else{ x = i - a[t] - 1; if( x > m ) m = x; } a[c ++] = i; } } if( s[i - 1] == s[i - 2] ){ x = i - a[c - 1]; if( x > m ) m = x; } printf( "Case %d: %d\n", k ++, m ); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator