题解 | 首字母大写

首字母大写

https://www.nowcoder.com/practice/91f9c70e7b6f4c0ab23744055632467a

#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    getline(cin,str);
    str=' '+str;
    bool isspace=true;
    for (int i = 0; i < str.size(); ++i) {
        if (str[i]>='a'&&str[i]<='z') {
            if (isspace){str[i]-=32;
                isspace=false;}}
        else if (str[i]==' ') isspace=true;
        else if (str[i]=='\t')isspace=true;

        else isspace= false;
    }
    str.erase(0,1);
    cout<<str;
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务