#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
void toLowerCase(char* str) {
for (int i = 0; str[i] != '\0'; ++i) {
str[i] = tolower(str[i]);
}
}
void toUpperCase(char* str) {
for (int i = 0; str[i] != '\0'; ++i) {
str[i] = toupper(str[i]);
}
}
void capitalizeWords(char* str) {
bool capitalize = true;
for (int i = 0; str[i] != '\0'; ++i) {
if (isspace(str[i])) {
capitalize = true;
}
else if (capitalize) {
str[i] = toupper(str[i]);
capitalize = false;
}
else {
str[i] = tolower(str[i]);
}
}
}
void normalizeString(char* str) {
int n = strlen(str);
int j = 0;
bool inWord = false;
for (int i = 0; i < n; ++i) {
if (!isspace(str[i])) {
if (inWord && j > 0 && str[j - 1] == ' ') str[j++] = ' ';
str[j++] = str[i];
inWord = true;
}
else if (inWord) {
str[j++] = ' ';
inWord = false;
}
}
if (j > 0 && str[j - 1] == ' ') --j;
str[j] = '\0';
}
int main() {
char input[100];
cout << "Nhap chuoi: ";
cin.getline(input, 100);
char temp[100];
void (*functions[])(char*) = { toLowerCase, toUpperCase, capitalizeWords, normalizeString };
const char* descriptions[] = { "Ky tu thuong", "Ky tu hoa", "Viet hoa moi tu", "Chuan hoa" };
for (int i = 0; i < 4; ++i) {
strcpy(temp, input);
functions[i](temp);
cout << descriptions[i] << ": " << temp << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2N0eXBlPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgdG9Mb3dlckNhc2UoY2hhciogc3RyKSB7CiAgICBmb3IgKGludCBpID0gMDsgc3RyW2ldICE9ICdcMCc7ICsraSkgewogICAgICAgIHN0cltpXSA9IHRvbG93ZXIoc3RyW2ldKTsKICAgIH0KfQoKdm9pZCB0b1VwcGVyQ2FzZShjaGFyKiBzdHIpIHsKICAgIGZvciAoaW50IGkgPSAwOyBzdHJbaV0gIT0gJ1wwJzsgKytpKSB7CiAgICAgICAgc3RyW2ldID0gdG91cHBlcihzdHJbaV0pOwogICAgfQp9Cgp2b2lkIGNhcGl0YWxpemVXb3JkcyhjaGFyKiBzdHIpIHsKICAgIGJvb2wgY2FwaXRhbGl6ZSA9IHRydWU7CiAgICBmb3IgKGludCBpID0gMDsgc3RyW2ldICE9ICdcMCc7ICsraSkgewogICAgICAgIGlmIChpc3NwYWNlKHN0cltpXSkpIHsKICAgICAgICAgICAgY2FwaXRhbGl6ZSA9IHRydWU7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKGNhcGl0YWxpemUpIHsKICAgICAgICAgICAgc3RyW2ldID0gdG91cHBlcihzdHJbaV0pOwogICAgICAgICAgICBjYXBpdGFsaXplID0gZmFsc2U7CiAgICAgICAgfQogICAgICAgIGVsc2UgewogICAgICAgICAgICBzdHJbaV0gPSB0b2xvd2VyKHN0cltpXSk7CiAgICAgICAgfQogICAgfQp9Cgp2b2lkIG5vcm1hbGl6ZVN0cmluZyhjaGFyKiBzdHIpIHsKICAgIGludCBuID0gc3RybGVuKHN0cik7CiAgICBpbnQgaiA9IDA7CiAgICBib29sIGluV29yZCA9IGZhbHNlOwoKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICAgICAgaWYgKCFpc3NwYWNlKHN0cltpXSkpIHsKICAgICAgICAgICAgaWYgKGluV29yZCAmJiBqID4gMCAmJiBzdHJbaiAtIDFdID09ICcgJykgc3RyW2orK10gPSAnICc7CiAgICAgICAgICAgIHN0cltqKytdID0gc3RyW2ldOwogICAgICAgICAgICBpbldvcmQgPSB0cnVlOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChpbldvcmQpIHsKICAgICAgICAgICAgc3RyW2orK10gPSAnICc7CiAgICAgICAgICAgIGluV29yZCA9IGZhbHNlOwogICAgICAgIH0KICAgIH0KICAgIGlmIChqID4gMCAmJiBzdHJbaiAtIDFdID09ICcgJykgLS1qOwogICAgc3RyW2pdID0gJ1wwJzsKfQoKaW50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