HDU 1862 Excel Sort (struct sort)

Source: Internet
Author: User

Excel SortTime limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 16387 Accepted Submission (s): 6137

problem DescriptionExcel can sort a set of records by any specified column. You are now asked to write programs to implement similar functions.
InputThe test input contains several test cases. The 1th line of each test case contains two integers n (<=100000) and C, where N is the number of records, and C is the column number that specifies the sort. The following are N
Row, each row contains a student record. Each student record consists of a school number (6 digits, no duplicate number in the same set of tests), a name (a string of no more than 8 digits without a space), a score (an integer in the closed interval [0, 100]), separated by 1 spaces between each item. When the n=0 is read, all input ends and the corresponding result is not output.

OutputFor each test case, the first output is 1 lines "Case I:", where I is the number of the test cases (starting from 1). Then, in N rows, the output is sorted according to the requirements, i.e. when c=1, the order is incremented by the number of studies, and when c=2, the non-descending dictionary order by name; when C=3
, sort by the non-descending order of the scores. When several students have the same name or the same score, they are incremented by their number.

Sample Input
3 1000007 James 85000010 Amy 90000001 Zoe 604 2000007 James 85000010 Amy 90000001 Zoe 60000002 James 984 3000007 James 850 00010 Amy 90000001 Zoe 60000002 James 900 0

Sample Output
Case 1:000001 Zoe 60000007 James 85000010 Amy 90Case 2:000010 Amy 90000002 James 98000007 James 85000001 Zoe 60Case 3:0000 60000007 Zoe James 85000002 James 90000010 Amy 90

SourceComputer Postgraduate Examination of University of Zhejiang University-2007
Puzzle : Structure sorting, attention to the classification condition when c=1,c=2,c=3
AC Code:
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring > #include <string> #include <cstdlib> #include <iomanip> #include <algorithm> #include <    Time.h>typedef Long Long ll;using namespace std;struct stud{int num;    Char name[10]; int score;} Stu[100001];int CMP1 (stud A,stud b) {return a.num<b.num;}    int CMP2 (stud A,stud b) {if (strcmp (a.name,b.name) ==0) return a.num<b.num; Return strcmp (A.name,b.name) <0;}    int Cmp3 (stud A,stud b) {if (A.score==b.score) return a.num<b.num; return a.score<b.score;}    int main () {int n,c,cas=1; while (cin>>n>>c) && (n| |        c) {memset (stu,0,sizeof (Stu));        for (int i=0; i<n; i++) scanf ("%d%s%d", &stu[i].num,stu[i].name,&stu[i].score);        if (c==1) sort (STU,STU+N,CMP1);        else if (c==2) sort (STU,STU+N,CMP2); else if (c==3) sort (stu,stu+N,cmp3);        printf ("Case%d:\n", cas++);    for (int i=0; i<n; i++) printf ("%06d%s%d\n", Stu[i].num,stu[i].name,stu[i].score); } return 0;}


 

HDU 1862 Excel Sort (struct sort)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.