1187. Three employees of the youngest age

Source: Internet
Author: User

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

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.