Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct{
- int grade,age;
- char name[15];
- }profile;
- void swape(profile* a,profile* b){
- profile c;
- c=*a;
- *a=*b;
- *b=c;
- }
- int main()
- {
- int n,la;
- scanf("%d %d",&n,&la);
- profile mon[n];
- for(int i=0;i<n;i++){
- scanf("%s",mon[i].name);
- scanf("%d %d",&mon[i].grade,&mon[i].age);
- }
- int flag;
- for(int i=0;i<n-1;i++){
- flag=0;
- for(int j=0;j<n-i;j++){
- if(mon[j].grade>mon[j+1].grade){
- flag=1;
- swape(&mon[j],&mon[j+1]);
- }
- }
- if(flag==0) break;
- }
- int i;
- for(i=la;i<n;i++){
- if(mon[i].grade!=mon[la-1].grade) break;
- }
- int count=i-1;
- for(i=0;i<count;i++){
- flag=0;
- for(int j=0;j<count-i+1;j++){
- if(mon[j].age<mon[j+1].age&&mon[j].grade==mon[j+1].grade){
- flag=1;
- swape(&mon[j],&mon[j+1]);
- }
- }
- if(flag==0) break;
- }
- for(i=la;i<n;i++){
- if(mon[i].grade!=mon[la-1].grade||mon[i].age!=mon[la-1].age) break;
- }
- count=i-1;
- for(i=0;i<count;i++){
- flag=0;
- for(int j=0;j<count-i+1;j++){
- if(mon[j].age==mon[j+1].age&&mon[j].grade==mon[j+1].grade&&(strcmp(mon[j].name,mon[j+1].name)<0)){
- flag=1;
- swape(&mon[j],&mon[j+1]);
- }
- }
- if(flag==0) break;
- }
- for(int k=0;k<la;k++){
- printf("%s\n",mon[k].name);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement