CINE MA POATE AJUTA CU UN PROGRAM IN C++ AM NEVOIE URGENT ???
Răspunsuri la întrebare
#include <iostream>
#include <fstream>
struct Elev {
std::string num_pren;
size_t nt, nam, np;
bool operator<(const Elev& b) const {
return np < b.np;
}
size_t nemotivate() const {
return nt - nam;
}
void calc() {
size_t nm = nemotivate();
np = nm > 50 ? 4 : np - nm / 10;
}
} *p;
std::ostream& operator<<(std::ostream& out, const Elev& e) {
return out << e.num_pren << ' ' << e.nt << ' ' << e.nam << ' ' << e.np;
}
void bubble_sort(Elev* lhs, Elev* rhs) {
size_t n = rhs - lhs;
for (size_t j, i = 0; i < n - 1; ++i)
for (j = 0; j < n - i - 1; ++j)
if (lhs[j] < lhs[j + 1])
std::swap(lhs[j + 1], lhs[j]);
}
int main() {
size_t n;
{
std::ifstream fin("purtare.in");
fin >> n;
p = new Elev[n];
for (size_t i = 0; i < n; ++i) {
fin >> p[i].num_pren >> p[i].nt >> p[i].nam >> p[i].np;
p[i].calc();
}
}
bubble_sort(p, p + n);
{
std::ofstream fout("purtare.out");
for (size_t i = 0; i < n; ++i)
fout << p[i] << '\n';
}
delete[] p;
}