# Matching element

Practice

Author: Anurag
Tester: Anurag
Editorialist: Anurag

# DIFFICULTY:

EASY,MEDIUM,GREEDY,STRING,CAKEWALK, SIMPLE

Math ,String

# PROBLEM:

Chef is given a some task he has given some number by person P and he has to arrange these numbers in chronogical order but after some observation he found that many of these numbers are matching so he has to first find out these matching numbers given by person .

but he is feeling very tired now you have to help him to find out these numbers

# EXPLANATION:

You have given some numbers in chronological order you have to you have to check which number is matching with another number in the given array if the number is matching with another we have to print that number in the given order

for example 3 4 8 4 3

In above example 3 and 4 are matching with another
so the output is 3 and 4

# SOLUTIONS:

[details=“Setter’s Solution”]
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void testcase()
{
// cin>>ws;
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if(a[i]==a[j]){
cout<<a[i]<<" ";
}
}
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}[/details]

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void testcase()
{
// cin>>ws;
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if(a[i]==a[j]){
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;
#define ll long long int
void testcase()
{
// cin>>ws;
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if(a[i]==a[j]){
cout<<a[i]<<" ";
}
}
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}