张老师的生日问题
private static void Demo()
{
List<int[]> list = new List<int[]>();
list.Add(new int[] { 3, 4 });
list.Add(new int[] { 3, 5 });
list.Add(new int[] { 3, 8 });
list.Add(new int[] { 6, 4 });
list.Add(new int[] { 6, 7 });
list.Add(new int[] { 9, 1 });
list.Add(new int[] { 9, 5 });
list.Add(new int[] { 12, 1 });
list.Add(new int[] { 12, 2 });
list.Add(new int[] { 12, 8 });
int count = 0;
List<int> list1 = new List<int>();//得到通过日期只出现一次的月份,即6,12月
foreach (int[] date
{
foreach (int[] date
{
if (date1[1] == date2[1])
{
count++;
}
}
if (count == 1)
{
list1.Add(date1[0]);
}
count = 0;
}
List<int[]> list2 = new List<int[]>();//得到6月,12月的所有日期
foreach (int i in list1)
{
foreach (int[] j in list)
{
if (i == j[0])
{
list2.Add(j);
}
}
}
//除掉月份为6,12的日期
foreach (int[] i in list2)
{
list.Remove(i);//得到(3,4)(3,5)(3,8),(9,1)(9,5)
}
//==============================================
List<int[]> list3 = new List<int[]>();//得到日期出现两次的
foreach (int[] date
{
foreach (int[] data
{
if (date1[1] == data2[1])
{
count++;
}
}
if (count > 1)
{
list3.Add(date1);
}
count = 0;
}
foreach (int[] i in list3)
{
list.Remove(i); //得到(3,4)(3,8)(9,1)
}
//=============================================
List<int[]> list4 = new List<int[]>();//月份重复数大于1个的
foreach (int[] date
{
foreach (int[] date
{
if (date1[0] == date2[0])
{
count++;
}
}
if (count > 1)
{
list4.Add(date1);
}
count = 0;
}
foreach (int[] i in list4)
{
list.Remove(i); //(9,1)
}
foreach (int[] j in list)
{
Console.WriteLine("张老师的生日为:" + j[0] + "月" + j[1] + "日");
}
Console.ReadLine();
}
每天进步一点点...