Student record

PROBLEM :

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
Rocky 66

--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------

#include<iostream>
using namespace std;
#include<string.h>

class student
{
string name ;
int n1,n2,n3 ;

public:
void getInput()
{
cin>>name ;
cin>>n1>>n2>>n3 ;
}

int getMaxAvg()
{
int sum ;
sum=n1+n2+n3 ;
return sum/3 ;
}

string Rname()
{
return name ;
}
} ;

int main()
 {
int t,no,i,avg ;
int mavg ;
string name ;
cin>>t ;
while(t--)
{
cin>>no ;
student s[no] ;
mavg=0 ;
name="" ;

for(i=0;i<no;i++)
s[i].getInput() ;

for(i=0;i<no;i++)
{
avg=s[i].getMaxAvg() ;
if(avg>mavg)
{
mavg=avg ;
name=s[i].Rname() ;
}
}

cout<<name<<" "<<mavg<<endl ;
}
return 0;
}

---------------------------------------------------------------------------------

Comments

Popular posts from this blog

Count ways to N'th Stair(Order does not matter)

Replace all ‘0’ with ‘5’ in an input Integer

Chocolate Distribution Problem

Remove characters from the first string which are present in the second string

Primality Test ( CodeChef Problem code: PRB01 )