SORT 6
QUESTION DESCRIPTION
MS .Dhoni want to play a game when the players are free in the dressing room.
Dhoni have given an array of n distinct elements, the task is to find all elements in array which have at-least two greater elements than themselves.
Dhoni declared a mandatory conditions like "void sort(int a[],int n)"
Examples:
Input : A[] = {2, 8, 7, 1, 5};
Output : 1 2 5
The output three elements have two or more greater elements
Input : A[] = {7, -2, 3, 4, 9, -1};
Output : -2 -1 3 4
Input:
The first line of input contains an integer T denoting the no of test cases.
Each test case contains two lines .
The first line of input contains an integer n denoting the size of the array.
Then in the next are n space separated values of the array.
Output:
For each test case in a new line print the space separated sorted values denoting the elements in array which have at-least two greater elements than themselves.
MS .Dhoni want to play a game when the players are free in the dressing room.
Dhoni have given an array of n distinct elements, the task is to find all elements in array which have at-least two greater elements than themselves.
Dhoni declared a mandatory conditions like "void sort(int a[],int n)"
Examples:
Input : A[] = {2, 8, 7, 1, 5};
Output : 1 2 5
The output three elements have two or more greater elements
Input : A[] = {7, -2, 3, 4, 9, -1};
Output : -2 -1 3 4
Input:
The first line of input contains an integer T denoting the no of test cases.
Each test case contains two lines .
The first line of input contains an integer n denoting the size of the array.
Then in the next are n space separated values of the array.
Output:
For each test case in a new line print the space separated sorted values denoting the elements in array which have at-least two greater elements than themselves.
TEST CASE 2
INPUT
INPUT
1
6
4 8 -1 6 7 -3
OUTPUT-3 -1 4 6
#include <iostream>
using namespace std;
void sort(int a[],int n)
{
int m;
for(int i=0;i<n-1;i++)
{
m=i;
for(int j=i+1;j<n;j++)
if(a[j]<a[m])
m=j;
int t=a[i];
a[i]=a[m];
a[m]=t;
}
}
void display(int a[],int n)
{
for(int i=0; i<n-2; i++)
cout<<a[i]<<" ";
cout<<endl;
}
int main() {
int t;
cin>>t;
while(t)
{
int n;
cin>>n;
int a[n];
for(int i=0; i<n; i++)
{cin>>a[i];}
sort(a,n);
display(a,n);
t--;
}
return 0;
}
Comments
Post a Comment