找出字符串中字符出现次数最的字符——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());
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());
相关文章推荐
- 笔试:找出一个字符串中字符出现最多的次数和该字符
- 找出一个字符串中出现次数最多的字符
- 给定一个字符串,找出这个字符串中出现最多的字符和次数
- 华为上机试题(java)找出一个字符串中出现次数最多的字符
- 找出一个字符串中重复最多的字符以及出现的次数
- 找出字符在字符串中出现的次数
- c语言编程----找出字符串中出现次数最多的字符
- JAVA找出字符串中连续出现次数最多的字符
- 找出字符串中出现次数最多的字符,和最大次数
- JS实现找出字符串中出现最多的字符和次数
- 找出字符在字符串中出现的次数
- Java实现给定任一字符串,长度为任意,要求找出其出现次数最多的字符及其出现次数。
- 找出字符串中字符出现次数最的字符
- 找出字符串中第一个出现次数最多的字符
- C/C+面试题一:找出字符串中出现最多的字符和次数,时间复杂度小于O(n^2)
- 给定一个字符串找出出现次数最多的字符
- js实现找出字符串中出现字数最多的字符并计算其出现次数
- 程序员面试指南(第六章) 数组和字符串(C#版) 1. 找出字符串中出现次数最多的字符及出现次数
- 给出一个字符串(不带空格),找出字符串当中出现次数最多的字符?
- [java] 找出字符串中出现最多的字符和出现的次数