HDU刷题日志(首字母变大写)

为了打好基础去学习算法,先刷完HDU11页的100道题,所以我希望每当我能独立解决一个时就记录下来,不仅仅让自己能够复习,也能够作为以后激励自己的动力

Problem Description
输入一个英文句子,将每个单词的第一个字母改成大写字母。
 

Input
输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。
 

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

Sample Input
 
  
i like acm i want to get an accepted
 

Sample Output
 
  
I Like Acm I Want To Get An Accepted

题目很简单,大家见笑了--------------------------------------------

#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>  
#include <stdlib.h>  
#include<string.h>
int main()
{
	int i = 1;
	char str[100];
	while (gets(str))           //为了把空格也输入进去
	{
		i = 0;
		for (i; i < strlen(str); i++)
		{
			if (str[i] ==32 && (97<= str[i + 1] && str[i] <= 122))str[i + 1] -= 32;
			if (i == 0)str[0] -= 32;
		}
		printf("%s\n", str);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_40879809/article/details/79675066