您的位置:首页 > 其它

找出字符串中字符出现次数最的字符——benwu资料

2010-03-20 17:12 176 查看
int count = testStr.Length;

            int max = 0;

            char cCurrent = ' ';

            List<char> list = new List<char>();

            for (int i = 0; i < count ;i++)

            {

                char c = testStr[i];

                if (cCurrent != c && !list.Contains(c))

                {

                    list.Add(c); //保存己经出现的字符

                    int scount = 0;

                    for (int j = 0; j < count; j++)//统计

                    {

                        if (testStr[j] == c)

                            scount++;

                    }

                    if (scount > max)

                    {

                        max = scount;

                        cCurrent = c;

                    }

                }

            }

            Consolse.Write("最长字符串:"+ cCurrent.ToString() + ";长度为" + max.ToString());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c list