Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string.h>
- using namespace std;
- int main()
- {
- int n,p;
- cin>>n>>p;
- struct elev
- {
- float n1,n2,n3;
- float medie;
- char nume[105],prenume[105];
- }x[105];
- for (int i=1;i<=n;i++)
- {
- cin>>x[i].nume>>x[i].prenume>>x[i].n1>>x[i].n2>>x[i].n3;
- x[i].medie=(x[i].n1+x[i].n2+x[i].n3)/3;
- }
- float mg=0;
- for (int i=1;i<=n;i++)
- mg+=x[i].medie;
- mg=mg/n;
- int c=0;
- if (p==1)
- {
- for (int i=1;i<=n;i++)
- if (x[i].medie>mg)
- c++;
- cout<<c;
- return 0;
- }
- if (p==2)
- {
- cout<<setprecision(3)<<mg<<endl;
- for (int i=1;i<n;i++)
- for (int j=i+1;j<=n;j++)
- {if (x[i].medie<x[j].medie)
- {
- elev aux=x[i];
- x[i]=x[j];
- x[j]=aux;
- }
- if (x[i].medie==x[j].medie)
- {if (strcmp(x[i].nume,x[j].nume)>0)
- {
- elev aux=x[i];
- x[i]=x[j];
- x[j]=aux;
- }
- if (strcmp(x[i].nume,x[j].nume)==0)
- {
- if (strcmp(x[i].prenume,x[j].prenume)>0)
- {
- elev aux=x[i];
- x[i]=x[j];
- x[j]=aux;
- }
- }
- }
- }
- for (int i=1;i<=n;i++)
- { int c=0;
- int n1=x[i].medie;
- while (n1)
- {
- c++;
- n1/=10;
- }
- cout<<x[i].nume<<" "<<x[i].prenume<<" "<<setprecision(c+2)<<x[i].medie<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement