# GPOS-Editorial

Practice

Author: Hari Vege

Easy

# PREREQUISITES:

Structures or pairs sorting

# PROBLEM:

Sorting Structures or pairs based on different parameters.

# EXPLANATION:

Just sort structure based on cgpa and year and print all 4 years \$bK\$b cgpa.

# SOLUTIONS:

Setter's Solution
``````            #include<iostream>
#include<algorithm>
using namespace std;
struct Klu
{
int id;
int year;
double gpa;
};
bool comparison(Klu a, Klu b)
{
return (a.gpa > b.gpa);
}
void printkluScheduling(Klu arr[], int n,int y)
{
sort(arr, arr+n, comparison);
int result[5]={0};
int ye[5]={0};
bool slot[n];
for (int i=0; i<n; i++)
slot[i] = false;
for (int i=0; i<n; i++)
{
ye[arr[i].year]++;
if(ye[arr[i].year]==y)
result[arr[i].year]=arr[i].id;
}
for(int i=1;i<5;i++){
if(result[i]!=0)
cout<<result[i]<<" ";
}
}
int main()
{  int n,i,j,y,k;
cin>>n;
while(n--){
/*Klu arr[] = { {170030673, 2, 9.6}, {170030675, 2, 9.1}, {170030676, 1, 2.7},
{170030677, 4, 2.5}, {170030678, 3, 1.5}}; */
//int n = sizeof(arr)/sizeof(arr[0]);
cin>>i;
Klu arr[i];
for(j=0;j<i;j++){
cin>>arr[j].id>>arr[j].year>>arr[j].gpa;}
cin>>y;
printkluScheduling(arr, i,y);

}
return 0;
}
``````