using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace StringSort { class Program { static void Main(string[] args) { StringSortAndNum(“ajhsdZzfjhAZKJSDK”); Console.ReadKey(); }
static void StringSortAndNum(String str) { String s1 = ""; for (int i = 65; i <91; i++) { foreach (char item in str) { if ((int)item == i) { s1 += item; } } foreach (char item in str) { if ((int)item == i+('a'-'A')) { s1 += item; } } } Dictionary<char, int> strAndNum = new Dictionary<char, int>(); foreach (char item in s1) { if (strAndNum.ContainsKey(item)) { strAndNum[item]++; } else { strAndNum.Add(item,1); } } Console.Write("排序后:"); Console.WriteLine(s1); foreach (var item in strAndNum) { Console.WriteLine("{0}出现次数:{1}",item.Key,item.Value); } } }