例如在 "aaa efaf feaf faefawef vsgrgs aaa efaf afergrgrg aaa"中那个字符串出现次数最多,出现多少次
解决方案 »
- 怎样让窗体出现滚动条
- 请教实时检测问题
- 怎么解决telnet一次只传送一个字符的问题
- 到底什么是跨线程调用?
- 奇怪的问题,ListView不能用AddRange
- dataGridView问题!
- 去除SortedList重复的键值
- sql 日期获得最新日期或获得小时:分:秒.毫秒
- 窗口上放了DataGrid,TopMost就无效,动态生成DataGrid也不行.真他妈不是人.急
- 再问一下,急!!!我在win2000上用C#+Access2000开发的应用程序,在98上该怎么安装?
- WINFORM 的 会的来 , 本人 有问题 请教 急急急急急急急急急急啊, (如何把一个程序里的文件导入到另一个解决方案进行编译,)
- 数组冒泡排序后,如何去掉最大值和最小值再算平均分?
比如:aaa中,aa字符串,出现次数怎么算,算1次还是算2次???
然后再确定怎么来算出现的次数
string str = "aaa efaf feaf faefawef vsgrgs aaa efaf afergrgrg aaa";
Dictionary<string, int> dic = new Dictionary<string, int>();
string[] temp = str.Split(' ');
foreach (string s in temp)
{
if (!dic.ContainsKey(s))
dic.Add(s, 1);
else
dic[s]++;
}
string most = string.Empty;
int count = 0;
foreach (string s in dic.Keys)
{
if (dic[s] > count)
{
most = s;
count = dic[s];
}
}
Console.WriteLine("出现最多的是:{0},共出现了{1}次", most, count);
foreach (string tmpStr in strs)
{
if (table[tmpStr] == null)
{
table[tmpStr] = 1;
}
else
{
table[tmpStr] = (int)table[tmpStr] + 1;
}
}
int maxCount = 0;
foreach (System.Collections.DictionaryEntry de in table)
{
if ((int)de.Value > maxCount)
{
maxCount = (int)de.Value;
}
}
System.Collections.ArrayList maxStr = new System.Collections.ArrayList(); foreach (System.Collections.DictionaryEntry de in table)
{
if ((int)de.Value == maxCount)
{
maxStr.Add(de.Key);
}
}
foreach (object obj in maxStr)
{
Console.Out.WriteLine((string)obj);
}