Sunday, 27 August 2017

STUDENT RECORD

A file contains data as follows( Student name, marks in
3 subjects)
Shrikanth 20 50 60
Kiran 30 80 90
Find the student who has maximum average score.

Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N,N is the number
of student.
The second line of each test case contains N input
Student name and marks in 3 subject.

Output:
Print the student who has maximum average score and maximum average score(in int).

Constraints:
1 ≤ T ≤ 10
1 ≤ N ≤ 15
1 ≤ s ≤ 10
1 ≤ marks ≤ 100

Example:

Input:
2
2
Shrikanth 20 30 10 Ram 100 50 10
3
Adam 50 10 40 Suresh 22 1 56 Rocky 100 90 10

Output:
Ram 53

#include <stdio.h>
int main() {
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,max=0,i,a,b,c,m,u=0;
        scanf("%d",&n);
        char s[n][100];
       for(i=0;i<n;i++)
         {
                scanf("%s",s[i]);
                scanf("%d%d%d",&a,&b,&c);
                m=(a+b+c)/3;
                if(m>max)
                {
                    max=m;
                    u=i;
                }
        }
        printf("%s %d\n",s[u],max);
    }
    return 0;
}

No comments:

Post a Comment