fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <cctype>
  4. using namespace std;
  5.  
  6. string normalizeName(const string &name) {
  7. stringstream ss(name);
  8. string word, result;
  9.  
  10. while (ss >> word) {
  11. word[0] = toupper(word[0]);
  12. for (size_t i = 1; i < word.size(); i++) {
  13. word[i] = tolower(word[i]);
  14. }
  15. result += word + " ";
  16. }
  17.  
  18. if (!result.empty()) {
  19. result.pop_back(); // Xóa khoảng trắng dư cuối cùng
  20. }
  21.  
  22. return result;
  23. }
  24.  
  25. int main() {
  26. int N;
  27. cin >> N;
  28. cin.ignore(); // Loại bỏ ký tự xuống dòng sau khi nhập số
  29.  
  30. while (N--) {
  31. string name;
  32. getline(cin, name);
  33. cout << normalizeName(name) << endl;
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.02s 5292KB
stdin
Standard input is empty
stdout