求经典算法,多多指教 求算一字符串中独立字符的个数。如string str="jsffff";其中 j,1s,1f,4 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Collections;namespace 字符统计{ class Program { static void Main(string[] args) { string myString = "uhifhiohskljhdsafipo喔喔 哈哈 你好啊"; Dictionary<char, int> myDictionary = MyMethod.GetInfoFormString(myString); foreach(KeyValuePair<char,int> kvp in myDictionary) { Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } } } public static class MyMethod { public static Queue<char> GetOnlyCharFromString(string str) { Queue<char> myQueue = new Queue<char>(); for (int i = 0; i < str.Length; i++) { if (myQueue.Contains(str[i]) == false) myQueue.Enqueue(str[i]); } return myQueue; } public static Dictionary<char,int> GetInfoFormString(string str) { Queue<char> myQueue = GetOnlyCharFromString(str ); Dictionary<char,int> myDictionary=new Dictionary<char,int>(); int oldQueueCount = myQueue.Count;//记录下它原有的量; for(int i=0;i<oldQueueCount ;i++) { char myChar=myQueue.Dequeue(); int num=0; for(int j=0;j<str.Length;j++) { if(str[j]==myChar) num++; } myDictionary.Add(myChar,num); } return myDictionary; } }} 验证事件怎么没有触发? c# 做一个简易论坛(在线等) 菜!如何给水晶报表设公式 c=a+b 串口怎么样收发16进制数据 新闻发布系统 C# 新手求救,顶者有分(3)? c#读取txt文件的指定列 怎样在ASP.net中弹出取时间的JavaScript窗口(在线等) MAC地址 C#调用C++写的动态链接库中函数的问题! 获取文件夹路径 关于Response.Write(JS)
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace 字符统计
{
class Program
{
static void Main(string[] args)
{
string myString = "uhifhiohskljhdsafipo喔喔 哈哈 你好啊";
Dictionary<char, int> myDictionary = MyMethod.GetInfoFormString(myString);
foreach(KeyValuePair<char,int> kvp in myDictionary)
{
Console.WriteLine("Key = {0}, Value = {1}",
kvp.Key, kvp.Value);
}
} }
public static class MyMethod
{
public static Queue<char> GetOnlyCharFromString(string str)
{
Queue<char> myQueue = new Queue<char>();
for (int i = 0; i < str.Length; i++)
{
if (myQueue.Contains(str[i]) == false)
myQueue.Enqueue(str[i]);
}
return myQueue;
}
public static Dictionary<char,int> GetInfoFormString(string str)
{
Queue<char> myQueue = GetOnlyCharFromString(str );
Dictionary<char,int> myDictionary=new Dictionary<char,int>();
int oldQueueCount = myQueue.Count;//记录下它原有的量;
for(int i=0;i<oldQueueCount ;i++)
{
char myChar=myQueue.Dequeue();
int num=0;
for(int j=0;j<str.Length;j++)
{
if(str[j]==myChar)
num++;
}
myDictionary.Add(myChar,num);
}
return myDictionary;
} }}