Răspuns:
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("purtare.in");
ofstream g("purtare.out");
struct elev {
int nmatr, nt,nam,np;
};
int main()
{
int n;
f >> n;
elev v[n];
int nanm;
for (int i=0; i<n; i++) {
f >> v[i].nmatr >> v[i].nt >> v[i].nam >> v[i].np;
nanm=v[i].nt-v[i].nam;
if (nanm>50) {
v[i].np=4;
}
else {
v[i].np=v[i].np-nanm/10;
}
}
for(int i = 0 ; i < n - 1 ; i ++) {
int p = i;
for(int j = i + 1 ; j < n ; j ++)
if(v[j].np > v[p].np)
p= j;
elev e = v[i];
v[i] = v[p];
v[p] = e;
}
for (int i=0; i<n; i++) {
g << v[i].nmatr << " " << v[i].nt << " " << v[i].nam << " " << v[i].np << endl;
}
return 0;
}
Explicație:
Succese!