Distinct number

Practice

//distinct number

Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD

DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

PREREQUISITES:

Math .

PROBLEM:

Chef is very clever boy , his mother given him a N number of tokens , at all the tokens there is some numbers are in that his mother told him to he has to arrange those tokens in non-increasing order but if there is same number of tokens then he has to remove those tokens . simply he has to remove duplicate and print it on non-increasing order .

EXPLANATION:

In the given problem there is some numbers on token we have to check every number if there is more than 1 same numbers of tokens then we have to remove it and print unique number of tokens in decreasing order .

for example:
N=5
3 1 3 4 5

in above example 5 number of token is given
In that one token number 3 is occurs two times that is we have to remove one token of number 3 then array becomes 3 1 4 5
then we have to sort the array in decreasing order and later print it .
that is 5 4 3 1

SOLUTIONS:

Setter's Solution

//distinct number
#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=n-1;i>=0;i–){
if(a[i]!=a[i-1]){
cout<<a[i]<<" ";
}
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution

//distinct number
#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=n-1;i>=0;i–){
if(a[i]!=a[i-1]){
cout<<a[i]<<" ";
}
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
void testcase()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=n-1;i>=0;i–){
if(a[i]!=a[i-1]){
cout<<a[i]<<" ";
}
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}