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