fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <map>
  4. #include <set>
  5. #include <cmath>
  6. #include <vector>
  7. #include <climits>
  8. #include <string>
  9. #include <algorithm>
  10. #include <sstream>
  11. #include <numeric>
  12. using namespace std;
  13.  
  14. vector<string> split(string haystack, string needle) {
  15. vector<string> result;
  16. int startPos = 0;
  17. int foundPos = haystack.find(needle, startPos);
  18. while (foundPos != string::npos) {
  19. int count = foundPos - startPos;
  20. string token = haystack.substr(startPos, count);
  21. if (!token.empty()) {
  22. result.push_back(token);
  23. }
  24. startPos = foundPos + needle.length();
  25. foundPos = haystack.find(needle, startPos);
  26. }
  27. string token = haystack.substr(startPos, haystack.length() - startPos);
  28. if (!token.empty()) {
  29. result.push_back(token);
  30. }
  31. return result;
  32. }
  33.  
  34. string nameConvert(const string& name) {
  35. const string DELIMITER = " ";
  36. stringstream builder;
  37. auto parts = split(name, DELIMITER);
  38. for (auto part : parts) {
  39. part[0] = toupper(part[0]);
  40. transform(part.begin() + 1, part.end(), part.begin() + 1, ::tolower);
  41. builder << part << DELIMITER;
  42. }
  43. return builder.str();
  44. }
  45.  
  46. string dateConvert(const string& date) {
  47. const string DELIMITER = "/";
  48. stringstream builder;
  49. auto parts = split(date, DELIMITER);
  50. builder << setw(2) << setfill('0') << parts[0] << DELIMITER;
  51. builder << setw(2) << setfill('0') << parts[1] << DELIMITER;
  52. builder << parts[2];
  53. return builder.str();
  54. }
  55.  
  56. class TeacherIDGenerator {
  57. private:
  58. inline static int index = 1;
  59. inline static const string PREFIX = "GV";
  60.  
  61. public:
  62. static string next() {
  63. stringstream builder;
  64. builder << PREFIX << setw(2) << setfill('0') << index;
  65. index++;
  66. return builder.str();
  67. }
  68. };
  69.  
  70. class Teacher {
  71. private:
  72. string id, name, major;
  73. public:
  74. Teacher() : name(""), major("") {
  75. id = TeacherIDGenerator::next();
  76. };
  77. Teacher(string name, string major) : name(name), major(major) {
  78. id = TeacherIDGenerator::next();
  79. };
  80.  
  81. public:
  82. void setName(string name) { this->name = name; }
  83. void setMajor(string major) { this->major = major; }
  84.  
  85. public:
  86. string toString() {
  87. stringstream builder;
  88. builder << id << " " << name << " ";
  89.  
  90. auto parts = split(major, " ");
  91. for (int i = 0;i < parts.size();i++) {
  92. builder << (char) toupper(parts[i][0]);
  93. }
  94. return builder.str();
  95. }
  96. public:
  97. bool operator < (const Teacher& other) const {
  98.  
  99. string first_name = split(name, " ").back();
  100. string other_name = split(other.name, " ").back();
  101.  
  102. if (first_name != other_name) {
  103. return first_name < other_name;
  104. }
  105. return id < other.id;
  106. }
  107. };
  108.  
  109. class TeacherFromKeyboardProvider {
  110. public:
  111. static Teacher next() {
  112. string buffer;
  113. Teacher t;
  114.  
  115. getline(cin, buffer);
  116. t.setName(buffer);
  117.  
  118. getline(cin, buffer);
  119. t.setMajor(buffer);
  120.  
  121. return t;
  122. }
  123. };
  124.  
  125. int main() {
  126. ios_base::sync_with_stdio(false);
  127. cin.tie(NULL);
  128. int n;cin >> n;
  129. cin.ignore();
  130. vector<Teacher> teachers;
  131. for (int i = 0;i < n;i++) {
  132. Teacher t = TeacherFromKeyboardProvider::next();
  133. teachers.push_back(t);
  134. }
  135.  
  136. sort(teachers.begin(), teachers.end());
  137.  
  138. for (auto teacher : teachers) {
  139. cout << teacher.toString() << endl;
  140. }
  141. return 0;
  142. }
  143.  
  144.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty