zoukankan      html  css  js  c++  java
  • 张老师的生日问题

            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>();//得到通过日期只出现一次的月份,即612

     

                foreach (int[] date1 in list)

                {

                    foreach (int[] date2 in list)

                    {

                        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);

                        }

                    }

                }

                //除掉月份为612的日期

                foreach (int[] i in list2)

                {

                    list.Remove(i);//得到(34)(35)(38),(91)(95

                }

     

                //==============================================

                List<int[]> list3 = new List<int[]>();//得到日期出现两次的

                foreach (int[] date1 in list)

                {

                    foreach (int[] data2 in list)

                    {

                        if (date1[1] == data2[1])

                        {

                            count++;

                        }

                    }

                    if (count > 1)

                    {

                        list3.Add(date1);

                    }

                    count = 0;

                }

     

                foreach (int[] i in list3)

                {

                    list.Remove(i); //得到(34)(38)(91

                }

     

                //=============================================

                List<int[]> list4 = new List<int[]>();//月份重复数大于1个的

                foreach (int[] date1 in list)

                {

                    foreach (int[] date2 in list)

                    {

                        if (date1[0] == date2[0])

                        {

                            count++;

                        }

                    }

                    if (count > 1)

                    {

                        list4.Add(date1);

                    }

                    count = 0;

                }

     

                foreach (int[] i in list4)

                {

                    list.Remove(i); //91

                }

     

                foreach (int[] j in list)

                {

                    Console.WriteLine("张老师的生日为:" + j[0] + "" + j[1] + "");

                }

                Console.ReadLine();

            }

  • 相关阅读:
    Python的map、filter、reduce函数
    C/C++中extern关键字详解
    python中的多继承
    用python爬虫抓站的一些技巧总结
    python中的OO
    互斥量、条件变量与pthread_cond_wait()函数的使用,详解
    C/C++ struct位结构(位域)
    VS2008无法启动asp.net提示“无法启动程序: http://localhost/.../test.aspx” 数据无效”。
    昨晚比较开心,QQ2009 sp6的0x00dd发送出去的包终于搞明白了
    CRC32 CRC16 校验算法 C# 代码
  • 原文地址:https://www.cnblogs.com/cyan/p/1606947.html
Copyright © 2011-2022 走看看