一个字符串中暴力的找出一个出现频率最高的字符


代码
 private string teststr(string temp)
    {     
        
int maxCount = 0;
        
string res = String.Empty;
        
while (temp.Length>0)
        {
            
string ts = temp.Substring(01);
            
int count = temp.Length;
            temp 
= temp.Replace(ts, "");
            count 
= count - temp.Length;
            
if (maxCount < count)
            {
                res 
= ts;
                maxCount 
= count;
            }
        }
        
return res;      
    }
  var s 
= teststr("4121111421421341234");

暴力的很。。。。

posted @ 2010-03-09 14:12  Godot  阅读(249)  评论(1编辑  收藏  举报