一组数据我如何判断才能打出这样的结果呢,1,1,2,2.2,3,2我如何打出2个1,2个2,一个2.2,一个3呢

解决方案 »

  1.   

    Response.Write("1,1,2,2.2,3");
      

  2.   

    string temp ="1,1,2,2.2,3,2";
      

  3.   

    split  
    循环   temp比较  数组记录  拼接字符串
      

  4.   

    split分组,冒泡排序,循环输出
      

  5.   

    string temp ="1,1,2,2.2,3,2";
    string[] str = temp.Split(',');
    Array.Sort(str);
      

  6.   


                string temp = "1,1,2,2.2,3,2";
                string[] array = temp.Split(',');
                Dictionary<string, int> dicCount = new Dictionary<string, int>();
                foreach (string s in array)
                {
                    if (!dicCount.ContainsKey(s))
                        dicCount.Add(s, 1);
                    else
                        dicCount[s]++;
                }
                StringBuilder sb = new StringBuilder();
                foreach (string s in dicCount.Keys)
                    sb.AppendFormat("{0}个{1},", dicCount[s], s);
                Response.Write(sb.ToString());
      

  7.   

    Dictionary<string, int> dicCount = new Dictionary<string, int>();这个什么意思
    问下
      

  8.   

    写的比较垃圾
        protected void Button1_Click(object sender, EventArgs e)
        {
            string temp = "1,1,2,1,2.2,3,9,9";
            string[] strArray = temp.Split(',');
            List<string> L = new List<string>(); 
            foreach(string s in strArray) 
            {
                L.Add(s);
            }        while(L.Count>0)
            {
                int iCount = 1;
                for (int i = 1; i < L.Count;i++)
                {
                    if (L[0] == L[i])
                    {
                        iCount++;
                        L.RemoveAt(i);
                        continue;
                    }
                }            Response.Write(iCount.ToString() + " 个 " + L[0] + "<br />");
                L.RemoveAt(0);
                continue;
            }
        }
      

  9.   

    10楼的思想不错,把数组转到有Key的列表里
      

  10.   


            string temp = "1,1,2,2.2,3,2";
            string[] str = temp.Split(',');
            Array.Sort(str);
            string strs="";
            int sum=0;
            string result="";
            for (int i = 0; i < str.Length; i++)
            {
                if (strs.Length==0)
                {
                    strs = str[i];
                    sum = 1;
                }
                else
                {
                    if (strs==str[i])
                    {
                        sum+=1;
                    }
                    else
                    {
                        result += "\n " + sum + "个" + strs;
                        strs = str[i];
                        sum = 1;
                    }
                }
            }
            result+="\n " + sum + "个" + strs;