08: Patient queuing, 08 patient queuing
08: Patient queuing
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
The procedure for registering a patient is as follows:
1. Elderly People (age> = 60 years) are given priority in seeing a doctor than non-elderly people.
2. The elderly are treated in the ascending order of age, and those of the same age are sorted by registration order.
3. non-elderly people see the doctor in the order of registration.
-
Input
-
Row 3: enter a positive integer smaller than 1st, indicating the number of patients;
The patient information is entered in each row according to the patient registration sequence, including: A string less than 10 represents the patient's ID (each patient's ID is different and only contains numbers and letters), an integer represents the patient's age, separated by a single space.
-
Output
-
Output the patient ID in the order of seeing a doctor. Each row has one.
-
Sample Input
-
5021075 40004003 15010158 67021033 75102012 30
-
Sample output
-
021033010158021075004003102012
-
Source
-
Exercise (14-6)
-
1 #include<iostream> 2 #include<cstdio> 3 using namespace std; 4 struct node 5 { 6 int xh; 7 int nl; 8 char id[1001]; 9 }a[10001];10 int main()11 {12 int n;13 cin>>n;14 for(int i=1;i<=n;i++)15 {16 scanf("%s",a[i].id);17 a[i].xh=i;18 cin>>a[i].nl;19 }20 for(int i=1;i<=n;i++)21 {22 for(int j=1;j<=n-1;j++)23 {24 if((a[j].nl<60&&a[j+1].nl>=60)||(a[j].nl<60&&a[j+1].nl<60&&a[j].xh>a[j+1].xh)||(a[j].nl>=60&&a[j+1].nl>=60&&a[j].nl<a[j+1].nl)||(a[j].nl>=60&&a[j+1].nl>=60&&a[j].nl==a[j+1].nl&&a[j].xh>a[j+1].xh))25 {26 swap(a[j].nl,a[j+1].nl);27 swap(a[j].xh,a[j+1].xh);28 swap(a[j].id,a[j+1].id);29 }30 }31 }32 for(int i=1;i<=n;i++)33 {34 printf("%s\n",a[i].id);35 }36 return 0;37 }