C++ Jounior

once setback,once inspiration,once self-awareness
重要的是这个磨练过程,而不是结果,要的是你粗壮的腿,而不是你身上背的那袋盐巴

 

求得含有最多连续特定字符个数的字符串

int  GetMaxCountofContinuousLetter( char   *  p, char  searchChar)
{
    
int  maxCount  = 0 ;
    
int  currentCount  =   0 ;
    
while ( 1 )
    
{
        
if ( * ==  searchChar)
        
{
            currentCount 
=   0 ;
            
while ( * &&   * ==  searchChar)
            
{
                currentCount 
++ ;
                p
++ ;
            }

            
if (maxCount  <  currentCount)
                maxCount 
=  currentCount;
        }

        
if ( * ==   ' \0 '
            
break ;
        
else
            p
++ ;
    }

    
return  maxCount;
}

int  main()     
{  
    
char   * p[ 3 ] =
    
{
        
" String(1)8818882348888856788888888988888888880 " ,
        
" String(2)881888234888885678888888898888888880 " ,
        
" String(3)8818882348888856788888888988888888888888880 "
    }
;
    
int  location  =   0 ;
    
char  searchChar  =   ' 8 ' ;
    
int  tempCount  =   0 ;
    
int  maxCount  =   0 ;
    
for ( int  i  =   0 ;i < sizeof (p) / sizeof ( * p);i ++ )
    
{
        tempCount 
=  GetMaxCountofContinuousLetter(p[i],searchChar);
        
if ( tempCount  >  maxCount)
        
{
            maxCount 
=  tempCount;
            location 
=  i;
        }

    }

    cout
<< " the string of maxCount is :  " << p[location] << endl;
    cout
<< " the count of  the continuous letters is :  " << maxCount << endl;
    cin.
get ();
}

posted on 2008-04-02 09:30 snowball 阅读(296) 评论(0)  编辑 收藏 引用 所属分类: 算法+数据结构


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

留言簿(1)

随笔分类

友情链接

搜索

最新随笔

最新评论

阅读排行榜