• 输出重复元素和不重复元素


     //输出重复的元素
            public static void ArrayDuplicate(int[] array1)
            {
                //string[] array1 = new string[] { "7ss", "4s", "7g", "1a","4g", "1e", "5e", "2a", "5e" };

                ArrayList list1 = new ArrayList(); //储存去重后剩余的元素
                ArrayList list2 = new ArrayList(); //储存重复的元素
                for (int i = 0; i < array1.Length; i++)
                {
                    if (!list1.Contains(array1[i]))
                        list1.Add(array1[i]);    //添加第一次出现的元素
                    else
                        list2.Add(array1[i]);    //添加重复的元素
                }
                foreach (int i in list1)
                {
                    Console.WriteLine(i);
                }
                Console.WriteLine("duplicate");
                foreach (int i in list2)
                {
                    Console.WriteLine(i);
                }
            }
            //输出不重复的元素
            public static void ArrayNoDuplicate(int[] array1)
            {
                //string[] array1 = new string[] { "7ss", "4s", "7g", "1a","4g", "1e", "5e", "2a", "5e" };


                ArrayList list1 = new ArrayList(); //储存去重后剩余的元素
                ArrayList list2 = new ArrayList(); //储存重复的元素
                for (int i = 0; i < array1.Length; i++)
                {
                    if (!list1.Contains(array1[i]))
                        list1.Add(array1[i]);    //添加第一次出现的元素
                    else
                    {
                        list1.Remove(array1[i]);
                        list2.Add(array1[i]);    //添加重复的元素
                    }
                }
                foreach (int i in list1)
                {
                    Console.WriteLine(i);
                }
                Console.WriteLine("duplicate");
                foreach (int i in list2)
                {
                    Console.WriteLine(i);
                }
            }

  • 相关阅读:
    stm32学习(一)
    linux驱动之ioctl
    request_threaded_irq()参数
    驱动初步学习
    linux命令操作
    Shell
    进程模块管理
    bash及正规表示法
    python脚本
    Python系统模块os
  • 原文地址:https://www.cnblogs.com/dasydong/p/3280971.html
Copyright © 2020-2023  润新知