文章

24

粉丝

0

获赞

253

访问

7.8k

头像
首字母大写 题解:
P1240 北京大学机考题
发布于2025年3月6日 18:26
阅读数 297

求助!!!PE了,AC60%哪里还需要改进

#include<bits/stdc++.h>
using namespace std;

int main() {
    vector<string> words;
    string s;
    while(getline(cin, s)) {
    	string word;
        int n = s.length();
        s[0] = toupper(s[0]);
        for(int i = 0; i < n; i ++) {
            if(s[i] == ' ' || s[i] == '\t' || s[i] == '\r' || s[i] == '\n') {
                s[i + 1] = toupper(s[i + 1]);
                words.push_back(word);
                word.clear();
            } else {
                word += s[i];
            }
        }
        words.push_back(word);
	    for(int i = 0; i < (int)words.size(); i ++) {
			cout << words[i];
			if(i < (int)words.size()) {
				cout << " ";
			}
		}
		cout << endl;
	    words.clear();
    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发