// File Name: hdu3746.cpp // Author: bo_jwolf // Created Time: 2013年05月04日 星期六 19:54:29 #include<vector> #include<list> #include<map> #include<set> #include<deque> #include<stack> #include<bitset> #include<algorithm> #include<functional> #include<numeric> #include<utility> #include<sstream> #include<iostream> #include<iomanip> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<ctime> using namespace std; const int maxn = 100010 ; char str[ maxn ] ; int next[ maxn ] ; void getnext( char *p ) { int j , k ; j = 0 , k = -1 ; int len = strlen( p ) ; next[ 0 ] = -1 ; while( j < len ) { if( k == -1 || p[ j ] == p[ k ] ) { j++ ; k++ ; next[ j ] = k ; } else k = next[ k ] ; } } int main() { int Case ; scanf( "%d" , &Case ) ; while( Case-- ) { scanf( "%s" , str ) ; getnext( str ); int len = strlen( str ) ; if( next[ len ] == 0 ) { printf( "%d\n" , len ) ; continue ; } int t = len - next[ len ] ; if( len % t == 0 ) printf( "0\n" ); else printf( "%d\n" , t - len % t ) ; } return 0; }
作者:liujie619406439 发表于2013-5-4 20:03:30 原文链接
阅读:53 评论:0 查看评论