Editorial for ONCE

PROBLEM LINK:Contest Page | CodeChef

Practice

Author: harsh_beniwal
Tester: harsh_beniwal
Editorialist: harsh_beniwal

DIFFICULTY:

EASY.

PREREQUISITES:

Math,Arrays.

PROBLEM:

Given an Array of size N. Which consist With N-1 repeating Elements. And a single element occurring only once. Find the Element which is occurring only once in whole array.

Check that the element that is occurring only once is Odd. if the number is Odd then print “PASS” else print “FALI”.

(NOTE:− It is sure that Only one Element will occur once)

QUICK EXPLANATION:

Here you have to find the element which is occurring only once in whole array.
And check if the number which occurred only once is odd or not.

If the number is odd then print “PASS” else print “FAIL”.

EXPLANATION:

We can find the element which is occurring only once with the help of array frequency count method. As the testcase are small up to 10^3 the frequency count method will work perfectly.

And check if the number which occurred only once is odd or not.
If the number is odd then print “PASS” else print “FAIL”.

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
int main()
{

int t;

cin>>t;

while(t–)

{

int n;

cin>>n;

int a[n],b[100007]={0};

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

{

    cin>>a[i];

}

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

{

    int k=a[i];

    b[k]++;

}

for(int i=0;i<100007;i++)

{

    if(b[i]==1)

    {

        if(i%2!=0)

        {

            cout<<"PASS"<<"\n";

        }

        else

        {

            cout<<"FAIL"<<"\n";

        }

    }

}

}

return 0;

}

Tester's Solution

#include<bits/stdc++.h>

using namespace std;

int main()

{

int t;

cin>>t;

while(t–)

{

int n;

cin>>n;

int a[n],b[100007]={0};

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

{

    cin>>a[i];

}

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

{

    int k=a[i];

    b[k]++;

}

for(int i=0;i<100007;i++)

{

    if(b[i]==1)

    {

        if(i%2!=0)

        {

            cout<<"PASS"<<"\n";

        }

        else

        {

            cout<<"FAIL"<<"\n";

        }

    }

}

}

return 0;

}

Editorialist's Solution

#include<bits/stdc++.h>

using namespace std;

int main()

{

int t;

cin>>t;

while(t–)

{

int n;

cin>>n;

int a[n],b[100007]={0};

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

{

    cin>>a[i];

}

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

{

    int k=a[i];

    b[k]++;

}

for(int i=0;i<100007;i++)

{

    if(b[i]==1)

    {

        if(i%2!=0)

        {

            cout<<"PASS"<<"\n";

        }

        else

        {

            cout<<"FAIL"<<"\n";

        }

    }

}

}

return 0;

}

1 Like