#include <iostream>
#include <cctype>
#include <string>
using namespace std;
string toLowerCase(const string& str) {
string result = str;
for (char& ch : result) {
ch = tolower(ch);
}
return result;
}
string toUpperCase(const string& str) {
string result = str;
for (char& ch : result) {
ch = toupper(ch);
}
return result;
}
string capitalizeWords(const string& str) {
string result = str;
bool capitalize = true;
for (char& ch : result) {
if (isspace(ch)) {
capitalize = true;
} else if (capitalize) {
ch = toupper(ch);
capitalize = false;
} else {
ch = tolower(ch);
}
}
return result;
}
string normalizeString(const string& str) {
string result;
bool inWord = false;
for (char ch : str) {
if (!isspace(ch)) {
if (inWord && !result.empty() && isspace(result.back())) {
result += ' ';
}
result += ch;
inWord = true;
} else if (inWord) {
result += ' ';
inWord = false;
}
}
if (!result.empty() && isspace(result.back())) {
result.pop_back();
}
return result;
}
int main() {
string input;
cout << "Nhap chuoi: ";
getline(cin, input);
cout << "Chuoi ky tu thuong: " << toLowerCase(input) << endl;
cout << "Chuoi ky tu hoa: " << toUpperCase(input) << endl;
cout << "Chuoi viet hoa moi tu: " << capitalizeWords(input) << endl;
cout << "Chuoi chuan hoa: " << normalizeString(input) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2N0eXBlPgojaW5jbHVkZSA8c3RyaW5nPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RyaW5nIHRvTG93ZXJDYXNlKGNvbnN0IHN0cmluZyYgc3RyKSB7CiAgICBzdHJpbmcgcmVzdWx0ID0gc3RyOwogICAgZm9yIChjaGFyJiBjaCA6IHJlc3VsdCkgewogICAgICAgIGNoID0gdG9sb3dlcihjaCk7CiAgICB9CiAgICByZXR1cm4gcmVzdWx0Owp9CgpzdHJpbmcgdG9VcHBlckNhc2UoY29uc3Qgc3RyaW5nJiBzdHIpIHsKICAgIHN0cmluZyByZXN1bHQgPSBzdHI7CiAgICBmb3IgKGNoYXImIGNoIDogcmVzdWx0KSB7CiAgICAgICAgY2ggPSB0b3VwcGVyKGNoKTsKICAgIH0KICAgIHJldHVybiByZXN1bHQ7Cn0KCnN0cmluZyBjYXBpdGFsaXplV29yZHMoY29uc3Qgc3RyaW5nJiBzdHIpIHsKICAgIHN0cmluZyByZXN1bHQgPSBzdHI7CiAgICBib29sIGNhcGl0YWxpemUgPSB0cnVlOwogICAgZm9yIChjaGFyJiBjaCA6IHJlc3VsdCkgewogICAgICAgIGlmIChpc3NwYWNlKGNoKSkgewogICAgICAgICAgICBjYXBpdGFsaXplID0gdHJ1ZTsKICAgICAgICB9IGVsc2UgaWYgKGNhcGl0YWxpemUpIHsKICAgICAgICAgICAgY2ggPSB0b3VwcGVyKGNoKTsKICAgICAgICAgICAgY2FwaXRhbGl6ZSA9IGZhbHNlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNoID0gdG9sb3dlcihjaCk7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJlc3VsdDsKfQoKc3RyaW5nIG5vcm1hbGl6ZVN0cmluZyhjb25zdCBzdHJpbmcmIHN0cikgewogICAgc3RyaW5nIHJlc3VsdDsKICAgIGJvb2wgaW5Xb3JkID0gZmFsc2U7CiAgICBmb3IgKGNoYXIgY2ggOiBzdHIpIHsKICAgICAgICBpZiAoIWlzc3BhY2UoY2gpKSB7CiAgICAgICAgICAgIGlmIChpbldvcmQgJiYgIXJlc3VsdC5lbXB0eSgpICYmIGlzc3BhY2UocmVzdWx0LmJhY2soKSkpIHsKICAgICAgICAgICAgICAgIHJlc3VsdCArPSAnICc7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmVzdWx0ICs9IGNoOwogICAgICAgICAgICBpbldvcmQgPSB0cnVlOwogICAgICAgIH0gZWxzZSBpZiAoaW5Xb3JkKSB7CiAgICAgICAgICAgIHJlc3VsdCArPSAnICc7CiAgICAgICAgICAgIGluV29yZCA9IGZhbHNlOwogICAgICAgIH0KICAgIH0KICAgIGlmICghcmVzdWx0LmVtcHR5KCkgJiYgaXNzcGFjZShyZXN1bHQuYmFjaygp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