using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _面试题
{
class Program
{
static void Main(string[] args)
{
//string str = "1一 2二 3三 4四 5五 6六 7七";
//string[] line = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
//Dictionary<char, char> dic = new Dictionary<char, char>();
//for (int i = 0; i < line.Length; i++)
//{
// dic.Add(line[i][0],line[i][1]);
//}
//Console.WriteLine("");
//string input = Console.ReadLine();
//for (int i = 0; i < input.Length; i++)
//{
// if (dic.ContainsKey(input[i]))
// {
// Console.WriteLine(dic[input[i]]);
// }
//}
//计算字符串每种字符出现的次数,welcome to china
string str = "welcome to china";
Dictionary<char, int> dic = new Dictionary<char,int>();
for (int i = 0; i < str.Length; i++)
{
if (dic.ContainsKey(str[i]))
{
dic[str[i]]++;
}
else
{
dic[str[i]] = 1;
}
}
foreach ( KeyValuePair<char,int> kv in dic)
{
Console.WriteLine("{0},出现的次数为{1}",kv.Key,kv.Value);
}
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _面试题
{
class Program
{
static void Main(string[] args)
{
//string str = "1一 2二 3三 4四 5五 6六 7七";
//string[] line = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
//Dictionary<char, char> dic = new Dictionary<char, char>();
//for (int i = 0; i < line.Length; i++)
//{
// dic.Add(line[i][0],line[i][1]);
//}
//Console.WriteLine("");
//string input = Console.ReadLine();
//for (int i = 0; i < input.Length; i++)
//{
// if (dic.ContainsKey(input[i]))
// {
// Console.WriteLine(dic[input[i]]);
// }
//}
//计算字符串每种字符出现的次数,welcome to china
string str = "welcome to china";
Dictionary<char, int> dic = new Dictionary<char,int>();
for (int i = 0; i < str.Length; i++)
{
if (dic.ContainsKey(str[i]))
{
dic[str[i]]++;
}
else
{
dic[str[i]] = 1;
}
}
foreach ( KeyValuePair<char,int> kv in dic)
{
Console.WriteLine("{0},出现的次数为{1}",kv.Key,kv.Value);
}
Console.ReadKey();
}
}
}