SHARE
TWEET

Untitled

a guest Dec 8th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef struct{
  5.     int grade,age;
  6.     char name[15];
  7. }profile;
  8. void swape(profile* a,profile* b){
  9.     profile c;
  10.     c=*a;
  11.     *a=*b;
  12.     *b=c;
  13. }
  14. int main()
  15. {
  16.     int n,la;
  17.     scanf("%d %d",&n,&la);
  18.     profile mon[n];
  19.     for(int i=0;i<n;i++){
  20.         scanf("%s",mon[i].name);
  21.         scanf("%d %d",&mon[i].grade,&mon[i].age);
  22.     }
  23.     int flag;
  24.     for(int i=0;i<n-1;i++){
  25.             flag=0;
  26.         for(int j=0;j<n-i;j++){
  27.             if(mon[j].grade>mon[j+1].grade){
  28.                 flag=1;
  29.                 swape(&mon[j],&mon[j+1]);
  30.             }
  31.         }
  32.         if(flag==0) break;
  33.     }
  34.     int i;
  35.     for(i=la;i<n;i++){
  36.         if(mon[i].grade!=mon[la-1].grade) break;
  37.     }
  38.     int count=i-1;
  39.     for(i=0;i<count;i++){
  40.             flag=0;
  41.         for(int j=0;j<count-i+1;j++){
  42.             if(mon[j].age<mon[j+1].age&&mon[j].grade==mon[j+1].grade){
  43.                 flag=1;
  44.                 swape(&mon[j],&mon[j+1]);
  45.             }
  46.         }
  47.         if(flag==0) break;
  48.     }
  49.     for(i=la;i<n;i++){
  50.         if(mon[i].grade!=mon[la-1].grade||mon[i].age!=mon[la-1].age) break;
  51.     }
  52.     count=i-1;
  53.     for(i=0;i<count;i++){
  54.         flag=0;
  55.         for(int j=0;j<count-i+1;j++){
  56.             if(mon[j].grade==mon[j+1].grade&&mon[j].age==mon[j+1].age&&(strcmp(mon[j].name,mon[j+1].name)<0)){
  57.                 flag=1;
  58.                 swape(&mon[j],&mon[j+1]);
  59.             }
  60.         }
  61.         if(flag==0) break;
  62.     }
  63.     for(int k=0;i<la;k++){
  64.         printf("%s\n",mon[k].name);
  65.     }
  66.     return 0;
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top