怎样在一个数组里面放7位数
string[,] s ={                
    {"5","8","6","17","22","30","25"},    
    {"5","9","4","14","18","1","5"},
  {"15","1","16","7","12","30","25"}, 
    {"5","8","25","17","15","25","4"},
    {"15","8","25","17","18","25","4"},
    {"5","25","17","17","32","25","4"}
      };
找出数组里面每一列位数出现率最高的,和出现率最底的?
例如:第一列出现了3个5 和2个15

解决方案 »

  1.   

    //参考如下代码        private class TextCount
            {
                public TextCount(string Text)
                {
                    this.Text = Text;
                    Count = 0;
                }
                public string Text;
                public int Count;
            }
            private static int CompareDinosByLength(TextCount A, TextCount B)
            {
                return B.Count - A.Count;
            }        private void button3_Click(object sender, EventArgs e)
            {
                string [,] s = {                
                    {"5", "8", "6", "17", "22", "30", "25"},    
                    {"5", "9", "4", "14", "18", "1", "5"},
                  {"15", "1", "16", "7", "12", "30", "25"}, 
                    {"5", "8", "25", "17", "15", "25", "4"},
                    {"15", "8", "25", "17", "18", "25", "4"},
                    {"5", "25", "17", "17", "32", "25", "4"}
                };
               
                for (int vCol = 0; vCol < 7; vCol++)
                {
                    textBox1.Text += string.Format("第{0}列", vCol) + "\r\n";
                    List<TextCount> vTextCounts = new List<TextCount>();
                    for (int vRow = 0; vRow < 6; vRow++)
                    {
                        TextCount vTextCount = null;
                        for (int i = 0; i < vTextCounts.Count; i++)
                        {
                            if (vTextCounts[i].Text == s[vRow, vCol])
                            {
                                vTextCount = vTextCounts[i];
                                break;
                            }
                        }
                        if (vTextCount == null)
                        {
                            vTextCount = new TextCount(s[vRow, vCol]);
                            vTextCounts.Add(vTextCount);
                        }
                        vTextCount.Count++;
                    }
                    vTextCounts.Sort(CompareDinosByLength);
                    for (int i = 0; i < vTextCounts.Count; i++)
                    {
                        textBox1.Text += vTextCounts[i].Text + "=" + 
                            vTextCounts[i].Count.ToString() + "\r\n";
                    }
                }
            }
      

  2.   

    用HASHTABLE做吧   扫到一个新的就当KEY,扫到一个重复的VALUE++
      

  3.   

    用hashtable
    ,请给个代码例子
    谢谢
      

  4.   

    都给说方法了 自己查MSDN去
    没事多去跑跑TopCoder  现在真是怀念在学校无忧无虑的玩TopCoder的时光