G-excel Sort hdu1424

Source: Internet
Author: User
Tags cas

G-excel Sort Time Limit:2000/1000 MS (java/others) Memory Limit: 128000/64000 KB (java/others) Submit Statusproblem 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 (<=1000)and C, where N is the number of records, and C is the column number of the specified sort. The following are N
Row, each row contains a student record. Each student record by the school number (6 digits, no duplicate number in the same set of tests)Name (a string that does not exceed 8 bits and does not contain spaces)Results (integer in closed interval [0, 100])Consisting of 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 results are sorted according to the requirements, i.e., when c=1, the order is incremented by the number of numbers, and when c=2, the non-descending dictionary order by name, and when C=3, by the non-descending order of grades. 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

1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4 Const intn=1e5+Ten;5 Const intinf=0x3f3f3f3f;6 intcas=1, T;7 intn,c;8 structStu9 {Ten     Charname[9]; One     intGrade,num; A     voidScan () {scanf ("%d%s%d",&num,name,&grade); } -     voidPrint () {printf ("%06d%s%d\n", Num,name,grade); } - }a[n]; the BOOLCMP1 (ConstStu&a,Conststu&b) - { -     returna.num<B.num; - } + BOOLCMP2 (ConstStu&a,Conststu&b) - { +     intx=strcmp (a.name,b.name); A     returnx<0|| x==0&& a.num<B.num; at } - BOOLCmp3 (ConstStu&a,Conststu&b) - { -     returnA.grade<b.grade | | A.grade==b.grade && a.num<B.num; - } - intMain () in { - //freopen ("1.in", "w", stdout); to //freopen ("1.in", "R", stdin); + //freopen ("1.out", "w", stdout); - //scanf ("%d", &t); the      while(SCANF ("%d%d", &n,&c) = =2&&N) *     { $          for(intI=0; i<n;i++) A[i].scan ();Panax Notoginseng         Switch(c) -         { the              Case 1: Sort (A,A+N,CMP1); Break; +              Case 2: Sort (A,A+N,CMP2); Break; A              Case 3: Sort (A,a+n,cmp3); Break; the         } +printf"Case %d:\n", cas++); -          for(intI=0; i<n;i++) A[i].print (); $     } $ //printf ("time=%.3lf\n", (double) clock ()/clocks_per_sec); -     return 0; -}
Solve.cpp

Exercises

Sort + 3 CMP

G-excel Sort hdu1424

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.