【王道机试】-字符串-首字母大写-北京大学

标注为较难的题,但是感觉就那样吧,记住转大写的函数。学校的复试题和leetcode难度相差太大了。

#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    getline(cin,s);
    if(s.length()!=0)
        s[0]=toupper(s[0]);
    for(int i=0;i<s.length();i++){
        if(s[i]==' '||s[i]=='\t'||s[i]=='\r'||s[i]=='\n')
            s[i+1]=toupper(s[i+1]);
    }
    cout<<s<<endl;
}

猜你喜欢

转载自blog.csdn.net/qq_39328436/article/details/114630798