问题 B: 首字母大写
时间限制: 1 Sec 内存限制: 32 MB
题目描述
对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。
在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\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 str[101];
int len;
bool flag=false;
while(gets(str))//必须这样写 输入有可能是多组测试数据 不是单点测试 而是多点测试
{
flag=false;
len=strlen(str);
for(int i=0; i<len; i++)
{
if(str[i]==' '||str[i]=='\t'||str[i]=='\r'||str[i]=='\n')
{
flag=true;
continue;
}
if(flag==true)
{
flag=false;
if(str[i]>='a'&&str[i]<='z')
{
str[i]=str[i]-32;
}
}
}
if(str[0]>='a'&&str[0]<='z')
{
str[0]=str[0]-32;
}
puts(str);
}
return 0;
}