1136: 首字母变大写 C语言

1136: 首字母变大写
时间限制: 1 Sec 内存限制: 128 MB
提交: 9777 解决: 5669
[状态] [讨论版] [提交] [命题人:admin]
题目描述
输入一个只包含大小写英文字母和空格的句子,将每个单词的第一个字母改成大写字母。

输入
输入一个长度不超过100的英文句子。

输出
请输出按照要求改写后的英文句子。

样例输入 Copy
i like ACM

样例输出 Copy
I Like ACM

#include <stdio.h>
#include <string.h>
#include <ctype.h>


// 首字母变大写 
int main() {
    
    
	char ch[100];
	int i;
	// 输入 
	gets(ch);
	for(i = 0; ch[i] != '\0'; i++){
    
    
		if(ch[i] == ' ' && ch[i + 1] != ' '){
    
    
			// 首字母变大写 
			if(islower(ch[i + 1]))
				ch[i + 1] = toupper(ch[i + 1]);
		}
	}
	if(islower(ch[0]))
		ch[0] = toupper(ch[0]);
	puts(ch); 
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_45306379/article/details/121511173