The principal of a school wants to speak with some of the students to assess their over all development including studies,most of the teachers were selecting the toppers of their classes but Mr,sam thought of an idea to select the bunch of students who did not have much difference in their marks so that he gains the reputation of a teacher who teaches well to the whole class and not just to a bunch of brilliant students.
Your are required to help mr,sam in selecting K students that can speak with principle from his class .you need to return an integer array representing the marks of the selected students sorted in ascending order.
Example1:
Input1:10
Innput2:{950,477,55,602,881,302,859,438,551,382}
Input3:1
Output:{950}
#include<iostream>
#include<algorithm>
using namespace std;
bool Descending(int x, int y)
{
if (x > y)return true;
else return false;
}
int main()
{
int numScores;
cout << "Please, enter a num of scores: ";
cin >> numScores;
int* arr = new int[numScores];
cout << "Please, enter " << numScores << " values: ";
for (int i = 0; i < numScores; i++)
{
cin >> arr[i];
}
sort(&arr[0], &arr[numScores], Descending);
int better;
cout << "Please, enter number of better scores: ";
cin >> better;
for (int i = 0; i < better; i++)
{
cout<<arr[i]<<" ";
}
delete []arr;
}
Comments
Leave a comment