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, dob, className;
  74. double gpa;
  75.  
  76. public:
  77. Student(string name, string dob, string className, double gpa) :
  78. name(name), dob(dob), className(className), gpa(gpa) {
  79. id = StudentIDGenerator::generate();
  80. };
  81.  
  82. public:
  83. string toString() {
  84. stringstream builder;
  85. builder << id << " " << nameConvert(name) << " " << className << " " << dateConvert(dob) << fixed << setprecision(2) << " " << gpa << endl;
  86. return builder.str();
  87. }
  88. };
  89.  
  90. int main() {
  91. ios_base::sync_with_stdio(false);
  92. cin.tie(NULL);
  93.  
  94. int t;cin >> t;
  95. for (int i = 1;i <= t;i++) {
  96. string name, className, dob;
  97. double gpa;
  98. cin.ignore();
  99.  
  100. getline(cin, name);
  101. getline(cin, className);
  102. getline(cin, dob);
  103.  
  104. cin >> gpa;
  105.  
  106. Student student{ name,dob,className,gpa };
  107.  
  108. cout << student.toString();
  109. }
  110. return 0;
  111. }
  112.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty