Monday, 6 March 2017

Geeksforgeeks Solution For " Student record "

GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

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.

Submit Your Solution :- Click Here 


Solution :-

Method 1 :- For Submitting in Geeks for geeks

#include <iostream>
using namespace std;

int main() 
{
int t,n,s1,s2,s3,avg;
string s,r;
cin>>t;
while(t--)
{
   cin>>n;
   cin>>s>>s1>>s2>>s3;
   r=s;
   avg=(s1+s2+s3)/3;
   n=n-1;
   while(n--)
   {
       cin>>s>>s1>>s2>>s3;
       if(((s1+s2+s3)/3)>avg)
       {
           avg=(s1+s2+s3)/3;
           r=s;
       }
   }
   cout<<r<<" "<<avg<<"\n";
   
}
return 0;
}

Method 2 :-

#include <iostream>
using namespace std;
struct student
{
    string name;
    int m1,m2,m3;
};

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       int n,i,sum=0;
       cin>>n;
       struct student s[n];
       string ch;
       for(i=0;i<n;i++)
       {
           cin>>s[i].name>>s[i].m1>>s[i].m2>>s[i].m3;
       }
        sum=(s[0].m1+s[0].m2+s[0].m3)/3;
        for(i=1;i<n;i++)
            {
                if((s[i].m1+s[i].m2+s[i].m3)>sum)
                {
                    sum=(s[i].m1+s[i].m2+s[i].m3)/3;
                    ch=s[i].name;
                }
            }
            cout<<ch<<" "<<sum;
            cout<<"\n";
    }
    return 0;
}

Output:-

Geeksforgeeks Solution For " Student record "

No comments:
Write comments

Recommended Posts × +