Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("clasa.in");
- struct elev
- {
- string nume,pren;
- double media1,media2,media3,mg;
- };
- elev el[101];
- int n,p,nrel,lv;
- double mgcls,scls;
- bool comp(elev i,elev j)
- {
- if(i.mg>j.mg)
- return 1;
- else if(i.mg==j.mg)
- {
- if(i.nume<j.nume)
- return 1;
- else if(i.nume==j.nume)
- {
- if(i.pren<j.pren)
- return 1;
- }
- }
- return 0;
- }
- int main()
- {
- string str;
- cin>>n>>p;
- cin.get();
- for(int i=0;i<n;++i)
- {
- getline(cin,str);
- vector<string>x;
- istringstream buffer(str);
- for(string w;buffer>>w;)
- x.push_back(w);
- for(unsigned int j=0;j<x.size();++j)
- switch(j)
- {
- case 0: el[lv].nume=x[j];break;
- case 1: el[lv].pren=x[j];break;
- case 2: el[lv].media1=stod(x[j]);break;
- case 3: el[lv].media2=stod(x[j]);break;
- case 4: el[lv].media3=stod(x[j]);break;
- }
- double s=el[i].media1+el[i].media2+el[i].media3;
- el[i].mg=s/3.0;
- el[i].mg=(el[i].mg*1000.0)/1000.0;
- scls=scls+el[i].mg;
- ++lv;
- }
- n=lv;
- mgcls=(double)scls/n;
- if(p==1)
- {
- for(int i=0;i<n;++i)
- if(el[i].mg>=mgcls)
- ++nrel;
- cout<<nrel<<'\n';
- return 0;
- }
- cout<<fixed<<setprecision(2)<<mgcls<<'\n';
- stable_sort(el,el+n,comp);
- for(int i=0;i<n;++i)
- cout<<fixed<<setprecision(2)<<el[i].nume<<' '<<el[i].pren<<' '<<el[i].mg<<'\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement