void correcter(string s, int j)
{
string correct;
for (; j < s.length(); j++)
{
if (int(s[j]) != 46){
if (int(s[j]) >= 97 && int(s[j]) <= 122 && i == 0)
{
char a = int(s[j]) - 32;
correct += a;
i++;
}
else if (int(s[j]) >= 65 && int(s[j]) <= 90&&i==0)
{
char a = int(s[j]) + 32;
correct += a;
i++;
}
else if (int(s[j]) >= 65 && int(s[j]) <= 90)
{
char a = int(s[j]) + 32;
correct += a;
i++;
}
else
correct += s[j];
}
else
{
correct += ". ";
i = 0;
}
}
cout << correct << endl;
}
問題是編寫一個代碼,將字符串的第一個字符轉換爲大寫字母,而其他字符保持小寫字母。在每一個「。」之後。先把字再放在上面,其他部分再放低!將小寫字母轉換爲大寫字母,並使其他字符保持較低
輸入:
hellOWOrLD.hELLOWORLD。
輸出:
爲HelloWorld。你好,世界。
它應該像圖片...
你的問題是?僅供參考:看看'std :: tolower'和'std :: toupper'。 – Rakete1111
以及它只能轉換第一或所有字符我的是轉換它的第一個字符加上使其他部分的單詞小寫,如示例input => hellOWOrLD.hELLOWORLD。輸出=>爲HelloWorld。你好,世界。 –