单个字用字典就好了 如果是词语,就用字典树
--找出字符串中出现次数最多的字符以及次数 private void test() { string str = "acbadbdfssdfaccadedse"; Dictionary<char, int> counter = new Dictionary<char, int>(); char max = str[0]; foreach (char c in str) { if (counter.ContainsKey(c)) { counter[c]++; } else { counter.Add(c, 1); } if (counter[max] < counter[c]) max = c; } string a = "出现次数最多的字符"+max+" 次数"+counter[max]; } 把哥的看家本事都使出来了
就是叫你在字符串中找出出现频率最高的字符
110,534
社区成员
642,575
社区内容
加载中
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧