浙江大学PAT---Basic Level---1004----成绩排名
2014-03-17 21:48
417 查看
题目:http://pat.zju.edu.cn/contests/pat-b-practise/1004
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace PAT_1004 { class Program { struct Stu_Info { public string name; public string school_number; public int score; }; static void Main(string[] args) { Console.WriteLine("请输入学生人数:"); int num_stu; num_stu=int.Parse(Console.ReadLine()); Stu_Info[] students = new Stu_Info[num_stu]; string inputs; for (int i = 0; i < num_stu; i++) { inputs = Console.ReadLine(); students[i]=GetStuInfo(inputs); } int[] index=GetHighLowScore(students); Console.WriteLine("{0} {1}", students[index[1]].name, students[index[1]].school_number); Console.WriteLine("{0} {1}", students[index[0]].name, students[index[0]].school_number); Console.ReadKey(); } /// <summary> /// 从输入信息中获取学生信息 /// </summary> /// <param name="info">输入信息</param> /// <returns>返回学生信息</returns> private static Stu_Info GetStuInfo(string info) { Stu_Info stu; int[] index = new int[2]; for (int i = 0; i < info.Length; i++) { if (info[i] == ' ') { if (index[0] == 0) { index[0] = i; } else { index[1] = i; } } } stu.name = info.Remove(index[0]); info = info.Remove(0, index[0]+1); stu.school_number = info.Remove(index[1] - index[0]-1); info = info.Remove(0, index[1] - index[0]); stu.score = Int32.Parse(info); return stu; } /// <summary> /// 获取最高分和最低分 /// </summary> /// <param name="students">学生信息</param> /// <returns></returns> private static int[] GetHighLowScore(Stu_Info[] students) { int[] index = new int[2]; for (int i = 1; i < students.Length; i++) { if (students[i].score < students[index[0]].score) { index[0] = i; } if (students[i].score > students[index[1]].score) { index[1] = i; } } return index; } } }
相关文章推荐
- PAT (Basic Level) Practise 的C++实现-1004.成绩排名
- PAT (Basic Level) Practise-1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文) 1004成绩排名(20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) Practise:1004. 成绩排名
- PAT(Basic Level)_1004_成绩排名
- PAT (Basic Level) Practise (中文)---1004 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- 【C++】浙大PAT (Basic Level)1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)- 1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20)
- PAT (Basic Level) 1004. 成绩排名 (20)
- PAT Basic Level 1004. 成绩排名 (20)
- PAT BASIC LEVEL 1004. 成绩排名 (20)
- PAT (Basic Level) Practise (中文)1004. 成绩排名 (20) C语言
- PAT(basic level) 1004 成绩排名
- Pat(Basic Level)Practice--1004(成绩排名)
- PAT (Basic Level)1004. 成绩排名
- 浙江大学PAT_乙级_1004. 成绩排名 (20)