zoukankan      html  css  js  c++  java
  • hdu3476Cyclic Nacklace

    点击打开链接




    // 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;
    }


  • 相关阅读:
    Web应用网络模型
    Http协议
    Array数组标准库
    Array数组基础
    javascript--Object
    javascript--Function
    letCode-3
    面试前的准备
    面试常见问题
    面试经验总结
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3059953.html
Copyright © 2011-2022 走看看