从一个记录了学生成绩的文本文档,每个学生成绩是一行,每 行是用|分割的数据,用|分割的域分别是姓名、年

龄、成绩,写程序取出成绩最高学生的姓名和成绩。参考:使用string[]lines=System.IO.File.ReadAllLines(@"c:\root.ini",... 龄、成绩,写程序取
出成绩最高学生的姓名和成绩。参考:使用string[] lines =
System.IO.File.ReadAllLines(@"c:\root.ini", Encoding.Default);从文本
文件读取数据,返回值为string数组,每个元素是一行。
展开
 我来答
664920886
2012-02-20
知道答主
回答量:1
采纳率:0%
帮助的人:1756
展开全部
第一步,在d盘编辑一个文本文档。例如定义:abc.txt。文本内容如下:
张旭|23|625
李黎明|13|653
王明|26|536|23|625
Tom|23|665
Jack|23|686
吴凯|23|546
李俊基|23|425
阿娇|23|25
第二步,复制下面代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 字符串函数
{
class Program
{

static void Main(string[] args)
{
JieGuo(); //调用函数static void JieGuo()
Console.ReadKey();
}
static void JieGuo()
{
string[] lines = System.IO.File.ReadAllLines(@"D:\abc.txt", Encoding.Default);
int c1=0;
for (int i = 0; i < lines.Length; i++)
{
int s1 = Fan(i); //调用函数static int Fan(int i2)
c1 = Max(c1, s1); //调用函数static int Max(int a,int b)
}
//Console.WriteLine("最高分:{0}",c1);
string b1 = Name(c1); //调用函数static string Name(int i2)

Console.WriteLine("最高分的人是{0},你考了{1}", b1, c1); //打印出的结果

}
static int Max(int a,int b)
{
int max;
if(a>b)
{
max=a;

}
else
max=b;
return max;
}
static int Fan(int i2)
{
string[] lines = System.IO.File.ReadAllLines(@"D:\abc.txt", Encoding.Default);
string a = lines[i2];
string[] b = a.Split('|');
int c = Convert.ToInt32(b[2]);
return c;
}
static string Name(int i2)
{
string[] lines = System.IO.File.ReadAllLines(@"D:\abc.txt", Encoding.Default);

string d="";
for (int i = 0; i < lines.Length; i++)
{

string a = lines[i];
string[] b = a.Split('|');
int c = Convert.ToInt32(b[2]);
if (c == i2)
{
d = b[0];
break;
}
}

return d;
}

}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式