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.  
  95. public:
  96. string getClassName() {
  97. return this->className;
  98. }
  99. string getID() {
  100. return this->id;
  101. }
  102. public:
  103. string toString() {
  104. stringstream builder;
  105. builder << id << " " << name << " " << className << " " << email << endl;
  106. return builder.str();
  107. }
  108.  
  109. public:
  110. bool operator <(const Student& other) {
  111. if (this->className != other.className) {
  112. return this->className < other.className;
  113. }
  114. return this->id < other.id;
  115. }
  116. };
  117.  
  118. class StudentFromKeyboardProvider {
  119. public:
  120. static Student next() {
  121. string buffer;
  122.  
  123. Student student;
  124.  
  125. getline(cin, buffer);
  126. student.setID(buffer);
  127.  
  128. getline(cin, buffer);
  129. student.setName(buffer);
  130.  
  131. getline(cin, buffer);
  132. student.setClass(buffer);
  133.  
  134. getline(cin, buffer);
  135. student.setEmail(buffer);
  136.  
  137. return student;
  138. }
  139. };
  140.  
  141. int main() {
  142. ios_base::sync_with_stdio(false);
  143. cin.tie(NULL);
  144.  
  145. int n;cin >> n;
  146. cin.ignore();
  147. vector<Student> students;
  148. for (int i = 0;i < n;i++) {
  149. Student student = StudentFromKeyboardProvider::next();
  150. students.push_back(student);
  151. }
  152.  
  153. int q;cin >> q;
  154. for (int i = 0;i < q;i++) {
  155. string value;cin >> value;
  156. cout << "DANH SACH SINH VIEN KHOA " << value << " :" << endl;
  157. for (int j = 0;j < students.size();j++) {
  158. if (students[j].getID().substr(0,4) == value) {
  159. cout << students[j].toString();
  160. }
  161. }
  162. }
  163. return 0;
  164. }
  165.  
  166.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty