老师在吗?用二维数组还是一维数组效率比较高呢?我现在用的是二维数组,代码如下
string[,] scores = new string[8,2]{{"景珍","90"},{"林惠洋","65"},{"成蓉","88"},{"洪南昌","70"},{"龙玉民","46"},{"单江开","81"},{"田武山","100"},{"王三明","68"}};
int avg=0;//平均分
for(int i=0;i<scores.GetLongLength(0);i++){
avg+=Convert.ToInt32(scores[i,1]);
}
avg = avg/8;
string name ="";//高于平均分的名字
for(int i=0;i<scores.GetLongLength(0);i++){
if(Convert.ToInt32(scores[i,1])>=avg){
name+=scores[i,0]+" ";
}
}
name = name.Trim(' ');
Console.WriteLine("平均分是{0},高于平均分的有:",avg);
Console.WriteLine(name);