题解 | #首字母大写#

首字母大写

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

#include <iostream>
using namespace std;

int main() {
    string str;
    while (getline(cin,str)) { // 注意 while 处理多个 case
        int index = 0;
        while (index < str.size() && (str[index] == ' ' ||
        str[index] == '\t' || str[index] == '\r' || str[index] == '\n')) {
            index++;
        }
        while (index < str.size()) {
            if (str[index] >= 'a' && str[index] <= 'z'){
                str[index++] = str[index] - 'a' + 'A';
            }
            while (index < str.size() && (str[index] != ' ' &&
            str[index] !='\t' && str[index] != '\r' &&str[index] != '\n'))
                index++;
            while (index < str.size() && (str[index] == ' ' ||
            str[index] == '\t' || str[index] == '\r' || str[index] == '\n')) 
                index++;
        }
        cout<<str<<endl;   
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

风的叶脉:不知道但我想要鞭打你( '-' )ノ)`-' ) 加油
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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