文章

211

粉丝

1

获赞

1223

访问

164.8k

头像

首字母大写 题解:

P1240 北京大学机考题
发布于 2026年1月
阅读数 677

#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 << endl;
    }
    return 0;
}*/

 



登录后发布评论

暂无评论,来抢沙发