Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstring>
- #include <cmath>
- using namespace std;
- struct elev
- {
- char nume[101],pren[101];
- int m1, m2, m3;
- float mg;
- } v[101];
- int main()
- {
- int n, p, i, k=0, j;
- double ma_clasei=0;
- cin>>n>>p;
- for(i=1; i<=n; i++)
- {
- cin>>v[i].nume>>v[i].pren>>v[i].m1>>v[i].m2>>v[i].m3;
- v[i].mg=(v[i].m1+v[i].m2+v[i].m3)/3.0;
- ma_clasei+=v[i].mg;
- }
- ma_clasei/=(1.0*n);
- ma_clasei=floor(ma_clasei * 100.0) / 100.0;
- if(p==1)
- {
- for(i=1; i<=n; i++)
- {
- if(v[i].mg>ma_clasei)
- k++;
- }
- cout<<k;
- }
- if(p==2)
- {
- cout<<fixed<<setprecision(2)<<ma_clasei<<endl;
- for(i=1; i<n; i++)
- {
- for(j=i+1; j<=n; j++)
- {
- if(v[i].mg<v[j].mg)
- swap(v[i],v[j]);
- if(v[i].mg==v[j].mg)
- {
- if(strcmp(v[j].nume,v[i].nume)<0)
- swap(v[i],v[j]);
- if(strcmp(v[j].nume,v[i].nume)==0)
- {
- if(strcmp(v[j].pren,v[i].pren)<0)
- swap(v[i],v[j]);
- }
- }
- }
- }
- for(i=1; i<=n; i++)
- {
- cout<<v[i].nume<<" "<<v[i].pren<<" "<<fixed<<setprecision(2)<<v[i].mg<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement