题解 | #首字母大写#
首字母大写
https://www.nowcoder.com/practice/91f9c70e7b6f4c0ab23744055632467a
#include<bits/stdc++.h>
using namespace std;
int main() {
string str;
getline(cin, str);//获取输入的字符串
//遍历字符串
for (int i = 0; i < str.length(); i++) {
//如果该字符为字母且位于首位或前一个字符为空白符,则转换为大写
if (isalpha(str[i]) && (i == 0 || isspace(str[i - 1]))) {
str[i] = toupper(str[i]);
cout << str[i];
}
//否则输出原字符
else {
cout << str[i];
}
}
}