zoukankan      html  css  js  c++  java
  • 输出重复元素和不重复元素

     //输出重复的元素
            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);
                }
            }

  • 相关阅读:
    C++ Tr1中的正則表達式
    html中#include file的使用方法
    InstallShield12豪华版破解版下载|InstallShield下载|软件打包工具
    linux-多线程
    使用 ArcGIS Online和APP进行监控操作和数据采集
    西藏印象:时光篇
    西藏印象:夜色篇
    西藏印象:蓝白篇
    hex2bin
    使用openssl的aes各种加密算法
  • 原文地址:https://www.cnblogs.com/dasydong/p/3280971.html
Copyright © 2011-2022 走看看