注意可能很长的字符哦也不是全是字母 考虑下算法效率哦
输入:aaacccbbb33322145@#$输出:
a 3
c 3
b 3
3 3
2 2
输入:aaacccbbb33322145@#$输出:
a 3
c 3
b 3
3 3
2 2
解决方案 »
- e.Item.Cell[0].Text
- C#操作Excel,Microsoft Jet 数据库引擎打不开文件''问题
- 数据采集问题
- 一个简单的正则表达式
- ArrayList中取值的问题
- 求助各位大虾?急急急!
- TCP发送数据丢失的原因
- 请问VS.Net中,“我最近的文件”“我最近的项目”那种菜单是如何作出来的?
- 请教:如何把Form上面的内容打印出来!谢谢!类似于pb里面的freefrom!!!
- C# 動態生成物件 和 MouseEvent 實現
- sqlserver 2000 telnet 能ping 通但是在打开数据库连接的时候经常出现 sqlserver不存在或是访问被拒绝,字符串的连接是正确的
- 关于out v和ref的使用
{
string result=string.Empty;
int len=text.Length;
while(len>0)
{
string temp=text[0].ToString();
text=text.Replace(temp,"");
int count=len-text.Length;
result+=temp+","+count+"\r\n";
len=text.Length;
}
return result;
}
using System.Collections.Generic;class A
{
static void Main()
{
string s = "aaacccbbb33322145@#$";
Dictionary<char,int> count = GetCharCount(s);
foreach (KeyValuePair<char,int> kvp in count)
{
Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value);
}
}
static Dictionary<char,int> GetCharCount(string text)
{
Dictionary<char,int> d = new Dictionary<char,int>();
foreach (char c in text)
{
if (d.ContainsKey(c)) d[c]++;
else d[c] = 1;
}
return d;
}
}
/* 程序输出:
a: 3
c: 3
b: 3
3: 3
2: 2
1: 1
4: 1
5: 1
@: 1
#: 1
$: 1
*/
using System.Collections.Generic;class A
{
static void Main()
{
string s = "aaacccbbb33322145@#$";
Dictionary<char,int> count = GetCharCount(s);
foreach (KeyValuePair<char,int> kvp in count)
{
if (kvp.Value > 1) Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value);
}
}
static Dictionary<char,int> GetCharCount(string text)
{
Dictionary<char,int> d = new Dictionary<char,int>();
foreach (char c in text)
{
int n;
d.TryGetValue(c, out n);
d[c] = n + 1;
}
return d;
}
}
/* 程序输出:
a: 3
c: 3
b: 3
3: 3
2: 2
*/
http://www.soasp.net/CShape/
http://www.soasp.net/CShape/