Hdoj 1862 Excel Sort

Source: Internet
Author: User
Tags strcmp

Excel sort

Time limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 14483 Accepted Submission (s): 5597


Problem Descriptionexcel can sort a set of records by any specified column. You are now asked to write programs to implement similar functions.

The input test inputs contain 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.

Output for each test case, first outputs 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 Input3 1000007 James 000010 Amy 000001 Zoe 4 2 000007 James 000010 Amy 000001 Zoe 60000002 James 984 3 000007 James 85000010 Amy 000001 Zoe 000002 James 90 0 0

Sample outputcase 1:000001 Zoe 60000007 James 85000010 Amy 90Case 2:000010 Amy 90000002 James 98000007 James-000001 Zoe Case 3:000001 Zoe 60000007 James 000002 James 000010 Amy 90 The main pit out lies in the sort of character array to note
#include <stdio.h> #include <string.h> #include <algorithm> #define MAX 100010using namespace std; struct Record{int Hao;char A[10];char s[10];int score;} Num[max];bool CMP1 (record A,record b) {return A.hao<b.hao;}    BOOL Cmp2 (record C,record D) {if (strcmp (C.S,D.S)!=0) return strcmp (C.S,D.S) <0; else return C.hao<d.hao;} BOOL Cmp3 (record E,record f) {if (E.score!=f.score) return E.score<f.score;elsereturn E.hao<f.hao;} int main () {int n,m,j,i,s,t,l;l=1;while (scanf ("%d%d", &n,&m) &&n!=0&&m!=0) {for (i=0;i<n;i + +) {num[i].hao=0;} for (i=0;i<n;i++) {scanf ("%s%s%d", &num[i].a,&num[i].s,&num[i].score), and for (j=0;j<6;j++) {num[i]. hao=num[i].hao*10+ (num[i].a[j]-' 0 ');}} if (m==1) {sort (NUM,NUM+N,CMP1);p rintf ("Case%d:\n", l); for (i=0;i<n;i++) {printf ("%s%s%d\n", Num[i].a,num[i].s, Num[i].score);}} else if (m==2) {sort (NUM,NUM+N,CMP2);p rintf ("Case%d:\n", l); for (i=0;i<n;i++) {printf ("%s%s%d\n", Num[i].a,num[i]. S,num[i].score);}} else if (m==3) {sort (nuM,num+n,cmp3);p rintf ("Case%d:\n", l); for (i=0;i<n;i++) {printf ("%s%s%d\n", Num[i].a,num[i].s,num[i].score);}} l++;} return 0;}

Hdoj 1862 Excel 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.