文章

23

粉丝

0

获赞

42

访问

1.1k

头像
首字母大写 题解:使用<cctype>:toupper
P1240 北京大学机考题
发布于2026年3月12日 16:16
阅读数 50

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

int main(){
    string s;

    while(getline(cin,s)){
        if(s.size()>0)
            s[0] = toupper(s[0]);

        for(int i=1;i<s.size();i++){
            if(s[i-1]==' ' || s[i-1]=='\t' || s[i-1]=='\r' || s[i-1]=='\n'){
                s[i] = toupper(s[i]);
            }
        }

        cout<<s<<endl;
    }

    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发