class Program
{
static void Main(string[] args)
{
//第一题
ChangeClass.ChangeChar();
//第二题
List<Worker> list = new List<Worker>();
list.Add(new Worker("zhang3", 18, 3000));
list.Add(new Worker("li4", 25, 3500));
list.Add(new Worker("wang5", 22, 3200));
list.Insert(1, new Worker("zhao6", 24, 3300));
list.RemoveAt(3);
for (int i = 0; i < list.Count; i++)
{
list[i].ShowMsg();
list[i].WorkTypeOf(list[i].Name);
}
Console.WriteLine(list[0].Equals("zhang3", 18, 3000));
//第三题
//随机a - z的字母50次,计算字符串中每种字符出现的次数 ,
//要求把结果存储在一个Dictionary集合中
Random r = new Random();
ArrayList arrChar = new ArrayList();
Dictionary<string, int> dic = new Dictionary<string, int>();
for (int i = 0; i < 50; i++)
{
arrChar.Add((char)r.Next(97,123)+"" );
if (dic.ContainsKey((string)arrChar[i]))
{
dic[(string)arrChar[i]]++;
}
else {
dic.Add((string)arrChar[i],1);
}
}
int js = 0;//计算出现的次数;
foreach (var item in dic.Keys)
{
js += dic[(string)item];
Console.WriteLine("出现的字母是: {0}, 次数是: {1}, 总共随机了:{2}次! ",item,dic[(string)item],js);
}
Console.ReadKey();
}
public class working : Worker
{
public working(string _name, int _age, double _salary)
: base(_name, _age, _salary)
{
this.Name = _name;
this.Age = _age;
this.Salary = _salary;
}
public override bool Equals(string name1, int age1, double salary1)
{
if (this.Name == name1 && this.Age == age1 && this.Salary == salary1)
{
return true;
}
return false;
}
}
}
class ChangeClass
{
public static void ChangeChar()
{
Again1:
Dictionary<string, int> Date = new Dictionary<string, int>();
Date.Add("零", 0);
Date.Add("一", 1);
Date.Add("二", 2);
Date.Add("三", 3);
Date.Add("四", 4);
Date.Add("五", 5);
Date.Add("六", 6);
Date.Add("七", 7);
Date.Add("八", 8);
Date.Add("九", 9);
Date.Add("十", 10);
Date.Add("十一", 11);
Date.Add("十二", 12);
Date.Add("二十", 20);
Date.Add("三十", 30);
Console.WriteLine("请输入中文日期:");
string Str = Console.ReadLine();
for (int i = 0; i < Str.Length; i++)
{
foreach (string j in Date.Keys)
{
if (!Str.Contains("年") || !Str.Contains("月") || !Str.Contains("日"))
{
Console.WriteLine("输入格式不对,请重新输入:");
goto Again1;
}
else
{
goto Again2;
}
}
}
Again2:
string Str1 = Str.Substring(0, Str.IndexOf("年"));
string Str2 = Str.Substring(Str.IndexOf("年") + 1, Str.IndexOf("月") - Str.IndexOf("年") - 1);
string Str3 = Str.Substring(Str.IndexOf("月") + 1, Str.IndexOf("日") - Str.IndexOf("月") - 1);
string Output = "";
int day = 0;
for (int i = 0; i < Str1.Length; i++)
{
foreach (string j in Date.Keys)
{
if ((Str1[i] + "") == j)
{
Output += Date[j] + "";
}
}
}
for (int i = 0; i < Str2.Length; i++)
{
foreach (string j in Date.Keys)
{
if ((Str2[i] + "") == j)
{
day += Date[j];
}
}
}
if (day < 10)
{
Output += "0" + day;
}
else
{
Output += day + "";
}
day = 0;
for (int i = 0; i < Str3.Length; i++)
{
foreach (string j in Date.Keys)
{
if ((Str3[i] + "") == j)
{
if (Str3[i] + "" == "十")
{
day *= Date[j];
}
else
{
day += Date[j];
}
}
}
}
if (day < 10)
{
Output += "0" + day;
}
else
{
Output += day + "";
}
Console.WriteLine(Output);
goto Again1;
}
}
public class Worker
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
private double salary;
public double Salary
{
get { return salary; }
set { salary = value; }
}
public Worker(string _name, int _age, double _salary)
{
name = _name;
age = _age;
salary = _salary;
}
public void ShowMsg()
{
Console.WriteLine("姓名:{0} 年龄:{1} 工资:{2}", this.Name, this.Age, this.Salary);
}
public void WorkTypeOf(string _names)
{
Console.WriteLine(_names + "努力搬砖!"); ;
}
public virtual bool Equals(string name1, int age1, double salary1)
{
if (this.Name == name1 && this.Age == age1 && this.Salary == salary1)
{
return true;
}
return false;
}
}