Medel Problem

indent preformatted text by 4 spaces

#include

#include<conio.h>

using namespace std;

int main()

{

int T;

cout<<“enter T”;

cin>>T;

while(T–)

{

int n,b,c,d;

int a[100];

cout<<“Enter n”;

cin>>n;

cout<<“Enter elements :”;

for(int i=0;i<=n-1;i++)

{

cin>>a[i];

}

for(int j=0;j<=n-3;j++)

{

if(a[0]<a[1]&&a[0]<a[2])

{

if(a[1]>a[2]){

b=a[1];

a[1]=a[2];

a[2]=b;

}

}

else if(a[0]>a[1]&&a[0]>a[2])

{

if(a[1]<a[2]){

d=a[1];

a[1]=a[2];

a[2]=d;

}

}

else if((a[0]>a[1]&&a[0]<a[2])||(a[0]<a[1]&&a[0]>a[2]))

{

c=a[0];

a[0]=a[1];

a[1]=c;

}

//cout<<"\n “<<a[0]<<” “<<a[1]<<” “<<a[2]<<”\n";

a[1]=a[2];

a[2]=a[j+3];

}

cout<<a[0]<<" ";

cout<<a[1];

}

return 0;

}

I tried to run this code in eclipse ide and it worked perfectly for me.

But when I tried to run this code in codechef’s ide and submitted this solution for the medel problem,I got wrong answer.I don’t understand where I commited a mistake.Your help is very appreciated.Please pardon the broken english I have used.

Thank You:smiley:

The problem is easy, just analyse different test-cases, and you will see that after removing all the medians from a tuple of three numbers, you will be left with the min and max element in the sequence.

Just keep track of the index of **min** and **max**, because in the output order matters.

**Refer the solution in C.**

**P.S: Refer to the following guidelines when you post again later.**

## Suggestions for asking the question on this forum.

- Format your code as the forum software messed it up.
- Give the link to problem which you are trying to solve.
- Explain your source-code in plain english, what idea you are trying to implement, yeah we can go through your code but it will be time consuming, it would be better if you explain it.

After doing the above things, then you can expect help from the community.

Thanks for Reading

Peace