码迷,mamicode.com
首页 > 编程语言 > 详细

查看一个int数组里边的每个数字出现过几次

时间:2014-12-10 17:51:56      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   for   on   div   log   cti   ad   

public void aa()
{
  int[] a = { 1, 2, 3, 4, 5, 4, 3, 2, 1 };
  Hashtable ht = new Hashtable();
  for (int i = 0; i < a.Length; i++)
  {
    if (ht.ContainsKey(a[i]))
    {
      ht.Add(a[i], (int)ht[i] + 1);
    }
    else
    {
      ht.Add(a[i], 1);
    }
  }
  string str = "";
  foreach (DictionaryEntry item in ht)
  {
    str += item.Key + ":" + item.Value + " ";
  }
}

  

查看一个int数组里边的每个数字出现过几次

标签:blog   io   ar   for   on   div   log   cti   ad   

原文地址:http://www.cnblogs.com/Zing/p/4155897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!