fork download
  1. #include <iostream>
  2. #include <cctype>
  3. using namespace std;
  4.  
  5. void ChuanHoa(string &str) {
  6. str[0] = toupper(str[0]);
  7. for (int i = 1; i < str.size(); i++)
  8. str[i] = tolower(str[i]);
  9. }
  10.  
  11. void InHoa(string &str) {
  12. for (char &c : str)
  13. c = toupper(c);
  14. }
  15.  
  16. int main() {
  17. int T; cin >> T;
  18. cin.ignore();
  19.  
  20. while (T--) {
  21. string S;
  22. getline(cin, S);
  23.  
  24. string name[100+5];
  25. int nameCnt = 0;
  26. string tmp;
  27.  
  28. for (char ch : S) {
  29. if (isalpha(ch)) {
  30. tmp += ch;
  31. } else if (!tmp.empty()) {
  32. name[nameCnt++] = tmp;
  33. tmp = "";
  34. }
  35. }
  36. if (!tmp.empty())
  37. name[nameCnt++] = tmp;
  38.  
  39. if (nameCnt == 0) continue;
  40.  
  41. for (int i = 1; i < nameCnt; i++) {
  42. ChuanHoa(name[i]);
  43. cout << name[i];
  44. if (i != nameCnt - 1)
  45. cout << ' ';
  46. }
  47. InHoa(name[0]);
  48. cout << ", " << name[0];
  49. cout << '\n';
  50. }
  51.  
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty