一个数组问题???
怎样在一个数组里面放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
------解决方案--------------------//参考如下代码
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);