NPTEL (WEEK-3)

Your college is organising a sporting event. The events are all done and now the task is to prepare the list of medal winners. The sports secretary for some reason assumed that the events will only have Gold and Silver medals but no Bronze medals. The contestants, especially the 3rd place winners were furious (understandably so!). To get things in control the secretary gives you the list of participants in an event and their standing in the event. Your task is to output the list of Bronze medalists in each of the events.

Each event has 10 participants.
Input:  The number of test cases T followed by T lines. Each line has 10 numbers that indicate the time taken by each contestant to complete the task. Each task takes less than or equal to 30 seconds. If there are two bronze winners, print the one with the lower id.
Output: The id of the contestant who secured the Bronze medal.

Example:
Input
1
16 12 34 11 10 5 3 1 15 21
Output
6
Explanation: The 1 in first line indicates that there is only one testcase. The third position is for the player who took 5 sec to finish the task. The player is in the 6th person in the input list. Note that the ids start at 1 and not at 0.



CODING :-


#include<stdio.h>
int sorting(int a[]);
int main()
{
    int num,a[10],b[10],r[100000];
    int i,j,k,l,temp;
    scanf("%d",&num);
    for(i=0;i<num;i++)
    {
        for(j=0;j<10;j++)
        {
            scanf("%d",&a[j]);
        }
        for(l=0;l<10;l++)
            b[l]=a[l];
        temp=sorting(b);
        for(k=0;k<10;k++)
        {
            if(temp==a[k])
            {
                r[i]=k+1;
                break;
            }
        }
    }
    for(i=0;i<num;i++)
    {
        printf("%d",r[i]);
        if(i!=num-1)
        {
            printf("\n");
        }
    }
    return 0;
}

int sorting(int a[10])
{
    int i,j,min,temp,ans;
    for(i=0;i<3;i++)
    {
        min=i;
        for(j=i+1;j<10;j++)
        {
            if(a[min]>a[j])
            {
                min=j;
            }
        }
        ans=a[min];
        temp=a[i];
        a[i]=a[min];
        a[min]=temp;
    }
    return ans;

}

No comments:

Post a Comment

How to install google-chrome in redhat without redhat subscription

Install google-chrome in redhat  Download the .rpm file of chrome https://www.google.com/chrome/thank-you.html?installdataindex=empty&st...