a数组中有大量数据,找出相同元素个数比其他相同元素个数明显多的个数b = {1,1,1,1,2,3,4,5,5,5,5,6,6,7,8,9,10}那么最后结果是1,5请教,谢谢

解决方案 »

  1.   


    using System;
    using System.Collections.Generic;
    using System.Text;namespace Collection
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[] arr = initArr();
                foreach (int i in arr)
                {
                    Console.Write(i + ",");
                }
                Console.WriteLine();
                Console.WriteLine("开始统计...");
                //----------------------------
                Dictionary<int, int> hashTable = new Dictionary<int, int>();
                foreach (int i in arr)
                {
                    if (!hashTable.ContainsKey(i))
                        hashTable[i] = 0;                hashTable[i]++;
                }            int maxNumber = 0;
                foreach (int i in hashTable.Keys)
                {
                    if (hashTable[i] > maxNumber)
                        maxNumber = hashTable[i];  //找到最大个数(hash表中的值)
                }
                foreach (int i in hashTable.Keys)
                {
                    if (hashTable[i] == maxNumber)
                        Console.WriteLine("数字{0},出现{1}次", i, hashTable[i]);
                }
                Console.ReadLine();
            }
            private static int[] initArr()
            {
                List<int> list = new List<int>();
                for (int i = 0; i < 3; i++)
                {
                    list.Add(1);
                }
                for (int i = 0; i < 5; i++)
                {
                    list.Add(3);
                }
                for (int i = 0; i < 7; i++)
                {
                    list.Add(5);
                }
                for (int i = 0; i < 7; i++)
                {
                    list.Add(6);
                }
                return list.ToArray();
            }
        }
    }
      

  2.   

    如果一个arraylist里有“〉”这样的点阵,那么怎么找出有几条线,谢谢~~">"不是真正的直线组合的...