一组数据我如何判断才能打出这样的结果呢,1,1,2,2.2,3,2我如何打出2个1,2个2,一个2.2,一个3呢 一组数据我如何判断才能打出这样的结果呢,1,1,2,2.2,3,2我如何打出2个1,2个2,一个2.2,一个3呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Response.Write("1,1,2,2.2,3"); string temp ="1,1,2,2.2,3,2"; split 循环 temp比较 数组记录 拼接字符串 split分组,冒泡排序,循环输出 string temp ="1,1,2,2.2,3,2";string[] str = temp.Split(',');Array.Sort(str); 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()); Dictionary<string, int> dicCount = new Dictionary<string, int>();这个什么意思问下 写的比较垃圾 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; } } 10楼的思想不错,把数组转到有Key的列表里 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; 如何在用户没输入完全的URL时也能访问到页面? [11.14]从数据库与从XML文件读取数据, 哪个效率高? .net2005 webconfig中调用数据库连接串问题? 请问VS2003中文简体版能否开发繁体版的软件 急!!! SQL 触发器 保持唯一的怎么实现啊?~ 数据绑定,如何绑定dataset其中的几列到datagrid1?? 问个ASP.NET问题,sValue[sValue.Length-1] reflector可以看到源代码吗? 请SQL高手赐一SQL语句!我的全部分都奉上了! 刚学ASP.NET,有点小问题想问问! 请教remove 局部刷新的问题.请指教
循环 temp比较 数组记录 拼接字符串
string[] str = temp.Split(',');
Array.Sort(str);
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());
问下
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;
}
}
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;