《算法笔记》3.6小节——入门模拟->字符串处理 问题 B: 首字母大写

版权声明:copyright©CodeIover reserved https://blog.csdn.net/qq_40073459/article/details/86559451

                                      问题 B: 首字母大写

题目描述

对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。
在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\t')、回车符('\r')、换行符('\n')。

输入

输入一行:待处理的字符串(长度小于100)。

输出

可能有多组测试数据,对于每组数据,
输出一行:转换后的字符串。

样例输入

if so, you already have a google account. you can sign in on the right.

样例输出

If So, You Already Have A Google Account. You Can Sign In On The Right.

实现代码:

#include <stdio.h> 
#include <string.h>
int main(){
	char word[101];
	while(gets(word)!=NULL){
		int len=strlen(word);
		int i=0; 
		do{
			if('a'<=word[i]&&word[i]<='z'){
				word[i]-=32;
			}
			for(i++;word[i]!=' '&&word[i]!='\t'&&word[i]!='\r'&&word[i]!='\n';i++);
			i++;	
		}while(word[i]!='\0');
		puts(word);
	}
	return 0;
}

结果如下:

猜你喜欢

转载自blog.csdn.net/qq_40073459/article/details/86559451