Title Description:
The employee has the employee number, name and age. Enter the information of N employees to find out the 3 youngest workers to print out.
Input:
Enter the first line to include 1 integer n,1<=n<=30, which represents the number of input data.
The next n rows have information about N employees:
Includes employee number (integer), name (string, length not exceeding 10), age (1<=age<=100).
Output:
There may be multiple sets of test data, for each set of data,
The number of output rows is a small value of N and 3, respectively, for the youngest employee information.
Keyword order: Age > Work number > Name, from small to large.
Sample input:
5501 Jack 6102 Nathon 100599 Lily 79923 Lucy 15814 Mickle 65
Sample output:
501 Jack 6923 Lucy 15814 Mickle 65
#include <iostream>#include<algorithm>#include<string.h>using namespacestd;structworker{intID; Charname[Ten]; intAge ;} buf[ -];BOOLCMP (worker A,worker b) {if(A.age!=b.age)returna.age<B.age; if(a.id!=b.id)returna.id<b.id; inttemp=strcmp (a.name,b.name); returntemp<0;}intMain () {intN,i; while(cin>>N) { for(i=0; i<n;i++) {cin>>buf[i].id>>buf[i].name>>Buf[i].age; } sort (Buf,buf+n,cmp); cout<<buf[0].id<<" "<<buf[0].name<<" "<<buf[0].age<<Endl; cout<<buf[1].id<<" "<<buf[1].name<<" "<<buf[1].age<<Endl; cout<<buf[2].id<<" "<<buf[2].name<<" "<<buf[2].age; } return 0;}
1187. Three employees of the youngest age