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 StudentIDGenerator {
  57. private:
  58. inline static string const PREFIX = "SV";
  59. inline static int const MAX = 3;
  60. inline static int index = 1;
  61.  
  62. public:
  63. static string generate() {
  64. stringstream builder;
  65. builder << PREFIX << setw(MAX) << setfill('0') << index;
  66. index++;
  67. return builder.str();
  68. }
  69. };
  70.  
  71. class Student {
  72. private:
  73. string id, name, className, email;
  74. public:
  75.  
  76. Student() : id(""), name(""), className(""), email("") {};
  77.  
  78. Student(string id, string name, string className, string email) :
  79. id(id), name(name), className(className), email(email) {
  80. };
  81. public:
  82. void setName(string name) {
  83. this->name = name;
  84. }
  85. void setClass(string className) {
  86. this->className = className;
  87. }
  88. void setEmail(string email) {
  89. this->email = email;
  90. }
  91. void setID(string id) {
  92. this->id = id;
  93. }
  94. public:
  95. string toString() {
  96. stringstream builder;
  97. builder << id << " " << name << " " << className << " " << email << endl;
  98. return builder.str();
  99. }
  100.  
  101. public:
  102. bool operator <(const Student& other) {
  103. if (this->className != other.className) {
  104. return this->className < other.className;
  105. }
  106. return this->id < other.id;
  107. }
  108. };
  109.  
  110. class StudentFromKeyboardProvider {
  111. public:
  112. static Student next() {
  113. string buffer;
  114.  
  115. Student student;
  116.  
  117. getline(cin, buffer);
  118. student.setID(buffer);
  119.  
  120. getline(cin, buffer);
  121. student.setName(buffer);
  122.  
  123. getline(cin, buffer);
  124. student.setClass(buffer);
  125.  
  126. getline(cin, buffer);
  127. student.setEmail(buffer);
  128.  
  129. return student;
  130. }
  131. };
  132.  
  133. int main() {
  134. ios_base::sync_with_stdio(false);
  135. cin.tie(NULL);
  136.  
  137. int n;cin >> n;
  138. cin.ignore();
  139. vector<Student> students;
  140. for (int i = 0;i < n;i++) {
  141. Student student = StudentFromKeyboardProvider::next();
  142. students.push_back(student);
  143. }
  144.  
  145. sort(students.begin(), students.end());
  146.  
  147. for (auto student : students) {
  148. cout << student.toString();
  149. }
  150. return 0;
  151. }
  152.  
  153.  
Success #stdin #stdout 0.01s 5300KB
stdin
Standard input is empty
stdout
Standard output is empty