下面这个函数 参数imformations 是一个以格式 如 520-lks-88 的字符串组成的一维数组,
格式对应的是 学号-姓名-分数 ,将一维数组分离然后组成二维数组,paixuById[x,y] 其中X就是一维数组imformations的
长度,y 是 字符串飞离出来的长度也就是3,请高手帮忙排下序,实现在 二维数组中将 学号从大到小,或者从小到大排列,
然后将一维数组以学号大小的顺序打印出来,话有点多!! static void outputbyId(string[] imformations)
{
string[,] paixuByid = new string[imformations.Length, 3];
for (int i = 0; i < imformations;i++)
{
string[] imfma = imformations[i].Split('-');
paixuByid[i, 0] = imfma[0];
paixuByid[i, 1] = imfma[1];
paixuByid[i, 2] = imfma[2];
}
for (int i = 0; i < paixuByid.Length / 3; )
{
int min = i;
for (int j = i + 1; j < paixuByid.Length / 3;j++ )
{
int temp;
if(int.Parse (paixuByid[j,0])<int.Parse (paixuByid [min,0]) )
}
} }
格式对应的是 学号-姓名-分数 ,将一维数组分离然后组成二维数组,paixuById[x,y] 其中X就是一维数组imformations的
长度,y 是 字符串飞离出来的长度也就是3,请高手帮忙排下序,实现在 二维数组中将 学号从大到小,或者从小到大排列,
然后将一维数组以学号大小的顺序打印出来,话有点多!! static void outputbyId(string[] imformations)
{
string[,] paixuByid = new string[imformations.Length, 3];
for (int i = 0; i < imformations;i++)
{
string[] imfma = imformations[i].Split('-');
paixuByid[i, 0] = imfma[0];
paixuByid[i, 1] = imfma[1];
paixuByid[i, 2] = imfma[2];
}
for (int i = 0; i < paixuByid.Length / 3; )
{
int min = i;
for (int j = i + 1; j < paixuByid.Length / 3;j++ )
{
int temp;
if(int.Parse (paixuByid[j,0])<int.Parse (paixuByid [min,0]) )
}
} }
解决方案 »
- 读取XML文件
- 连接数据库时候怎样使用相对路径?
- WebService自动报警功能如何做
- datagridview怎样同时实现插入和分页
- 为什么数据新增后,用reader读出来是空值???
- 如何对C#.NET中的TextBox输入完成按<回车>后能直接执行ImagesButton服务器控件里的代码?
- propertyGrid控件的下拉框问题请教
- 用window.open 打开子窗体后,想关闭父窗体如何实现?
- 如何在c#的程序中嵌入word和excel(高分200求)!!!!!
- json
- C#写一下调用存储过程的代码(谢绝直接复制)
- 如何得到两个List<T>对象a和b的交集c。即c中的元素全是a和b中共同的元素。
static void outputbyId(string[] imformations)
{
Array.Sort(imformations, (x, y) =>
{
var i=int.Parse(x.Substring(0,x.IndexOf("-")));
var j=int.Parse(y.Substring(0,x.IndexOf("-")));
if(i>j)
return 1;
else if(i<j)
return -1;
else
return 0;
});
//排好序的一维数组
foreach (var t in imformations)
{
Console.WriteLine(t); } string[,] paixuByid = new string[imformations.Length, 3];
for (int i = 0; i < imformations.Length; i++)
{
string[] imfma = imformations[i].Split('-');
paixuByid[i, 0] = imfma[0];
paixuByid[i, 1] = imfma[1];
paixuByid[i, 2] = imfma[2];
}
//输出二维数组
for (int i = 0; i < paixuByid.GetUpperBound(0); i++)
{
Console.WriteLine(paixuByid[i, 0]);
}
}
static void outputbyId(string[] imformations)
{
string[,] paixuByid = new string[imformations.Length, 3];
for (int i = 0; i < imformations;i++)
{
string[] imfma = imformations[i].Split('-');
paixuByid[i, 0] = imfma[0];
paixuByid[i, 1] = imfma[1];
paixuByid[i, 2] = imfma[2];
}
for (int i = 0; i < paixuByid.Length / 3; )
{
int min = i;
for (int j = i + 1; j < paixuByid.Length / 3;j++ )
{
Object temp;
if(int.Parse (paixuByid[j,0]) <int.Parse (paixuByid [min,0]) )
min=j;
temp=paixuByid[j,0];
paixuByid[j,0]=paixuByid [min,0];
paixuByid [min,0]=temp;
}
} }
还是说必须要按照要求先分成二维排序再输出?
{
public int Compare(object x, object y)
{
string s1 = (string)x;
string s2 = (string)y;//下面的排序规则自己写吧
int year1 = int.Parse(s1.Substring(0, s1.IndexOf("年")));/
int year2 = int.Parse(s2.Substring(0, s2.IndexOf("年")));
int m1 = int.Parse(s1.Substring(s1.IndexOf("年") + 1, 2));
int m2 = int.Parse(s2.Substring(s2.IndexOf("年") + 1, 2));
int i = (year1-year2)*12+m1-m2;
return -i;
}
}
最简单就这样了: string[] informations = new string[3];
informations[0]= "587-lks-88";
informations[1]= "512-jku-98";
informations[2]= "556-art-65";
Array.Sort(informations);
foreach(string s in informations)
Console.WriteLine(s);