#includebitsstdc++husing namespace std;struct patient string id; int age; int ord;;patient p9999999;bool cmppatient apatient b ifaage=60&&bage=60 return aagebage; else ifaage=60&&bage60 return tr
The given code is used to sort a list of patients based on their age and priority. The patients are represented as a struct with attributes for ID, age, and order.
The cmp() function is used as a comparison function for sorting the patients. It compares the ages of two patients and returns true if the first patient is older than the second patient. If both patients are 60 years or older, it compares their ages and returns true if the first patient is older. If both patients are under 60 years, it compares their order of appearance and returns true if the first patient appeared earlier.
In the main function, the number of patients is taken as input. Then, for each patient, their ID, age, and order of appearance are taken as input and stored in the struct array. The sort() function is then used to sort the patients using the cmp() function as the comparison function. Finally, the IDs of the patients are printed in the sorted order
原文地址: http://www.cveoy.top/t/topic/iWyX 著作权归作者所有。请勿转载和采集!