Header Ads Widget

Dedication Level = Infinity

 Problem:-

A simple question again..!

These are the people from nirmaLand who have shown utmost dedication towards Competitve Programming..!

You will be provided with name of the coder and no. of hours he/she spent on coding.

You need to output top 3 names of the coders who spent most time in coding.

Note: Time (no. of hours) given for all coders will be unique. More technically, no two coders will have same amount of time.

See the sample case for better understanding.

Input format:

First line consist of total number of coders, let's say 'n'.

Each of the next n lines consist of a string, let's say 'N' (name of coder) and a number let's say, 'T' (time).


Output format:

Output names of top 3 coders that spent maximum time in coding.

Constraints:

3 <= n <= 100

1 <= |N| <= 10

1 <= T <= 1000

Sample Input
7
Darshan 78
Harshad 90
Jaimin 87
Nirav 88
Hardik 1
Fenil 70
Lovlin 5
Sample Output
Harshad
Nirav
Jaimin
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Harshad spent 90 hours in coding, which is maximum, so his name is at first.

After Harshad, Nirav spent 88 hours in coding, which is maximum, so his name is second.

After Nirav, Jaimin spent 87 hours in coding, which is maximum, so his name comes third.

COde:-

#include<stdio.h>
#include<string.h>
int main()
{
    int n,a[100];
    char name[100][10],s[10];
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
scanf("%s",name[i]);
     scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
if(a[i]<a[j])
         {
             int temp;
             temp=a[i];
             a[i]=a[j];
             a[j]=temp;
             strcpy(s,name[i]);
             strcpy(name[i],name[j]);
             strcpy(name[j],s);
         }
        }
    }
    for(int i=0;i<3;i++)
    {
        printf("%s\n",name[i]);
    }
    return 0;
}




Post a Comment

0 Comments