文章

150

粉丝

0

获赞

556

访问

23.0k

头像
首字母大写 题解:
P1240 北京大学机考题
发布于2026年1月29日 09:27
阅读数 171

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

int main(){
	char str[105];
	while(cin.getline(str, 105)){
		int tag = 1;
		int len = strlen(str);
		for(int i=0;i<len;i++){
			if(tag == 1 && !isspace(str[i])){
				if( str[i] >= 'a' && str[i] <= 'z' )
					str[i] = str[i] - 'a' + 'A'; //str[i] = toupper(str[i]);
				tag = 0;
			}
			else if(isspace(str[i]))
				tag = 1;
		}
		cout << str << endl;
	}	
	return 0;
}


/*int main() {
    char str[105];
    while (cin.getline(str, 105)) {
        int len = strlen(str);
        bool newWord = true;
        for (int i = 0; i < len; i++) {
            if (newWord && !isspace(str[i])) {
                if (islower(str[i])) {
                    str[i] = toupper(str[i]);
                }
                newWord = false;
            } else if (isspace(str[i])) {
                newWord = true;
            }
        }
        cout << str << e...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发