C++ Bc. 36 cpp
#include <vector> #include <algorithm> #include <string> #include <sstream> #include <iostream> #include <iomanip> struct Student { int body; std::string hodnoceni; Student(std::string); bool operator< (const Student& s) const { return body < s.body; } }; typedef std::vector<Student> Prehled; int main() { std::istringstream inp("Adam Jan G61 : A 1 3 1 1 F 5 H 1 1 K 2 M N \n" "Soukup Petr H62 : 1 1 1 D E 1 G H I J K L M N \n" "Valenta Karel G66 : 2 3 4 2 3 4 5 5 1 1 5 5 1 1 \n" "Zachrta D. H62 : A B C D E F G H I J K L M N \n"); Prehled p; std::string zaznam; while (getline(inp, zaznam)) { Student s(zaznam); p.push_back(s); } std::sort(p.begin(), p.end()); for (Prehled::const_reverse_iterator i=p.rbegin(), e=p.rend(); i!=e; i++) { std::cout << std::setw(3) << i->body << " " << i->hodnoceni << std::endl; } } Student::Student(std::string zaznam) { for (int i=zaznam.size(); i>=0; i--) // absence (A-N) je hodnocena 0 body if (zaznam[i] == ':') break; else switch (zaznam[i]) { case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': zaznam[i] = '0'; default: ; } hodnoceni = zaznam; body = 0; std::istringstream data(zaznam); char z; while (data >> z && z != ':'); // preskocim textovou cast int cviceni; while (data >> cviceni) body += cviceni; // nactu body ze cviceni }
[ Zpět ]