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