联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2018-11-21 10:03

Homework 1

Sorting

Time Limit: 20 seconds

You are asked to implement a tiny Java program to sort student score records.

The score report has the following format:

(a) The first line contains the number of records, says N (N ≥ 1).

(b) Each of the next N lines contains a comma separated list of student’s

StudentID, Student Name, Course Code and his/her obtained Score.

StudentID starting with ‘s’ occupies totally 11 characters.

Student Name is a varied string from 5 to 14 characters.

Course Code is a fixed 5-character string.

Score is an integer ranging from 0 to 100.

(c) You may assume there is no space before and after the comma delimiter

and there is no trailing space after each line of data.

You are required to display the report according to StudentID, student

name, course code and the score in either an ascending order or a descending

order.

Your system shall be efficient in both searching and sorting. In particular,

the running time for a single query of your system shall be less than 20 seconds

with the number of records N is less than 100,000. Therefore, please try

to call faster algorithms (e.g. quick sort, merge sort and binary search trees,

etc.) to implement your system.

Input Specification

The first line specifies N records in a student-record report. The coming N

lines are the student records. After N lines of student records, there are queries

regarding to sorting options. For example, “1 A” represents sorting on the first

field in an ascending order (“D” denotes the descending order). The queries

end with a 0.

Output Specification

Regarding to each sorting query, your program should print the sorted report

according to the specified field in either ascending order or descending order.

After each output, your program should give an extra newline except for the

last output report.

Sample Input

5

s1109853011,JackieChan,CS001,85

s0907451244,FrankPapadias,MA002,65

s0308893477,MirandaLambert,HM467,35

1

s4045128481,SophiaPam,CM604,75

s0812340023,PhilipsChiu,CS001,71

1 A

1 D

2 A

2 D

3 A

3 D

4 A

4 D

0

Output for the Sample Input

s0308893477,MirandaLambert,HM467,35

s0812340023,PhilipsChiu,CS001,71

s0907451244,FrankPapadias,MA002,65

s1109853011,JackieChan,CS001,85

s4045128481,SophiaPam,CM604,75

s4045128481,SophiaPam,CM604,75

s1109853011,JackieChan,CS001,85

s0907451244,FrankPapadias,MA002,65

s0812340023,PhilipsChiu,CS001,71

s0308893477,MirandaLambert,HM467,35

s0907451244,FrankPapadias,MA002,65

s1109853011,JackieChan,CS001,85

s0308893477,MirandaLambert,HM467,35

s0812340023,PhilipsChiu,CS001,71

s4045128481,SophiaPam,CM604,75

s4045128481,SophiaPam,CM604,75

s0812340023,PhilipsChiu,CS001,71

s0308893477,MirandaLambert,HM467,35

s1109853011,JackieChan,CS001,85

s0907451244,FrankPapadias,MA002,65

s4045128481,SophiaPam,CM604,75

s0812340023,PhilipsChiu,CS001,71

s1109853011,JackieChan,CS001,85

s0308893477,MirandaLambert,HM467,35

s0907451244,FrankPapadias,MA002,65

s0907451244,FrankPapadias,MA002,65

s0308893477,MirandaLambert,HM467,35

s0812340023,PhilipsChiu,CS001,71

s1109853011,JackieChan,CS001,85

s4045128481,SophiaPam,CM604,75

2

s0308893477,MirandaLambert,HM467,35

s0907451244,FrankPapadias,MA002,65

s0812340023,PhilipsChiu,CS001,71

s4045128481,SophiaPam,CM604,75

s1109853011,JackieChan,CS001,85

s1109853011,JackieChan,CS001,85

s4045128481,SophiaPam,CM604,75

s0812340023,PhilipsChiu,CS001,71

s0907451244,FrankPapadias,MA002,65

s0308893477,MirandaLambert,HM467,35


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp