3g:如何查找一个字符串中重复次数最多的字符,返回这个字符的个数和字符
来源:互联网 发布:手机版电音制作软件 编辑:程序博客网 时间:2024/05/17 22:44
算法一: using System;using System.Collections.Generic;using System.Text;class Program...{ private static SortedDictionary<char, int> sd = new SortedDictionary<char, int>(); static void Main(string[] args) ...{ string str = "1232143546534135164161"; foreach(char c in str) ...{ Check(c); } char maxChar = Char.MinValue; int maxValue = 0; foreach(KeyValuePair<char, int> kvp in sd) ...{ Console.WriteLine("Dictionary has a Key : {0} and Value: {1}", kvp.Key, kvp.Value); if(kvp.Value > maxValue) ...{ maxValue = kvp.Value; maxChar = kvp.Key; } } Console.WriteLine("Max char is {0}, times is {1}.", maxChar, maxValue); Console.ReadLine(); } private static void Check(char c) ...{ if(sd.ContainsKey(c))//有了 ...{ sd[c]++; } else ...{ sd.Add(c, 1); } }} 算法2List<char> list = new List<char>(); string s = "ghjajikdnkxxxxfvnjxxzkxxxnfjkdmfn"; list.AddRange(s.ToCharArray()); list.Sort(); char c=' '; int temp = 1; char maxChar=' '; int maxCount=0; for (int i = 0; i < list.Count; i++) ...{ if (i > 0) ...{ if (list[i] == c) ...{ temp++; } else ...{ temp = 1; } } if (temp > maxCount) ...{ maxCount = temp; maxChar = list[i]; } c = list[i]; } Console.WriteLine(maxChar.ToString()+" "+maxCount.ToString()); 算法3string ss = "fdsafjkdlsajifnalkdnaslkf"; char[] c = ss.ToCharArray(); ArrayList al1 = new ArrayList(); ArrayList al2 = new ArrayList(); int i = 0; int k = 0; foreach ( char cc in c) ...{ if (!al1.Contains(cc)) ...{ al1.Add(cc); al2.Add(1); } else ...{ al2.Insert(al1.IndexOf(cc),Convert.ToInt32(al2[al1.IndexOf(cc)].ToString()) + 1); al2.RemoveAt(al1.IndexOf(cc) + 1); } } for ( int j=0;j<al2.Count;j++ ) ...{ if ( Convert.ToInt32(al2[j].ToString()) > i) ...{ i = Convert.ToInt32(al2[j].ToString()); k = j; } } string s = "字符" + al1[k].ToString() + "出现" + i.ToString() + "次"; 算法4string s = "skjfklsaghtqw rmq vwec ruwuiey vbre wur q"; StringBuilder sb = new StringBuilder(s); List<int> charCount = new List<int>(); List<char> lchar = new List<char>(); int i, j; i = 0; j = 1; while (sb.Length > 0 && i<sb.Length) ...{ charCount.Add(1); lchar.Add(sb[0]); while (sb.Length > 0 && j<sb.Length) ...{ if (sb[0] == sb[j]) charCount[i]++; j++; } sb.Replace(sb[0].ToString(), ""); i++; j = 1; } for (int k = 0; k < charCount.ToArray().Length; k++) ...{ Console.WriteLine(string.Format("{0,4} {1}", lchar[k].ToString(), charCount[k])); } Console.ReadLine();
- 3g:如何查找一个字符串中重复次数最多的字符,返回这个字符的个数和字符
- 如何查找一个字符串中重复次数最多的字符,返回这个字符的个数和字符
- 算法: 返回一串字符串中重复次数最多的字符
- 给定一个字符串,找出这个字符串中出现最多的字符和次数
- javascript判断一个字符串中出现次数最多的字符,统计这个次数
- 判断一个字符串中出现次数最多的字符,统计这个次数
- 判断一个字符串中出现次数最多的字符,统计这个次数
- 判断一个字符串中出现次数最多的字符,并统计这个次数
- 判断一个字符串中出现次数最多的字符,统计这个次数
- 判断一个字符串中出现次数最多的字符,统计这个次数
- 判断一个字符串中出现次数最多的字符,统计这个次数
- 判断一个字符串中出现次数最多的字符,统计这个次数
- 判断一个字符串中出现次数最多的字符,并统计这个次数
- 五十、判断一个字符串中出现次数最多的字符,并统计这个次数
- 查找字符串中出现最多次数的字符及其个数
- 统计字符串中出现次数最多的字符及个数
- java【通用】统计字符串中重复【单个】字符的次数频次并输出重复最多的次数和字符
- 找出一个字符串中重复最多的字符以及出现的次数
- Android 近百个项目的源代码
- 二叉排序树
- 华为员工标准岗位工资明细及分析
- 说说Xcode4中xib绑定的原理
- UIViewController Class Reference
- 3g:如何查找一个字符串中重复次数最多的字符,返回这个字符的个数和字符
- Ibatis3中基于接口,class对象调用的例子
- DP HDU 1494
- 计划-USACO
- zoj 1530 Find The Multiple(bfs)
- 1.1.1 Your Ride Is Here
- 3g:Get与Post,Head的区别
- 插入排序
- mysql获取刚插入(添加)记录的自动编号id