Excel can sort a set of records by any specified column. You are now asked to write programs to implement similar functions.
Input
The 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.
Output
For 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
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace Std;
struct Stu//define struct body
{
int z;
Char x[7],y[9];
}ST[100000];
BOOL Cam1 (stu A,stu B)//Sorting by number of studies
{
Return strcmp (a.x,b.x) <0;
}
BOOL Cam2 (stu A,stu B)//Sort by name
{
if (strcmp (A.Y,B.Y) ==0)
Return strcmp (a.x,b.x) <0;
Return strcmp (A.Y,B.Y) <0;
}
BOOL Cam3 (stu A,stu B)//Order of achievement
{
if (A.Z==B.Z)
Return strcmp (a.x,b.x) <0;
Return a.z<b.z;
}
int main ()
{
int n,c,d,i,t,cas=1,sum;
while (~SCANF ("%d%d", &n,&c))
{
i=0;t=n;sum=0;
while (n--)
{
scanf ("%s%s%d", &st[i].x,&st[i].y,&st[i].z);
if (strlen (st[i].x) <=6&&strlen (ST[I].Y) <=8&&0<=st[i].z&&st[i].z<=100)// Determine if input values meet demand
sum++;
i++;
}
if (sum==i&&t!=0&&0<c<4)
{
Sort (st,st+t,cam1);
for (d=0,i=0;i<t-1;i++)
if (strcmp (st[i].x,st[i+1].x) ==0)//exclusion number the same error condition.
d=1;
if (d==0)
{
if (c==2)
{
Sort (st,st+t,cam2);
}
if (c==3)
{
Sort (ST,ST+T,CAM3);
}
printf ("Case%d:\n", cas++);
for (i=0;i<t;i++)
printf ("%s%s%d\n", st[i].x,st[i].y,st[i].z);
}
}
}
return 0;
}
Experience: For the further familiarity and use of the structure, the mistakes of many times let me pay more attention to the conditions given by the topic.
Sequencing Training 5, B-2