题解 | #首字母大写#
首字母大写
https://www.nowcoder.com/practice/91f9c70e7b6f4c0ab23744055632467a
#include<iostream> #include<string> using namespace std; int main() { string str; getline(cin, str); str = " " + str + " "; for (int i = 1; i < str.length(); ++i) { if (str[i] >= 'a' && str[i] <= 'z' && (str[i - 1] == ' '||str[i-1]=='\t'||str[i-1]=='\n'||str[i-1]=='\r')) { str[i] = str[i] - 32; } } str.pop_back(); str.erase(0, 1); cout << str << endl; return 0; }