Problem Link:点击打开链接
题目描述
对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。 在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\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.
AC code:
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<map>
#include<math.h>
#include<string.h>
#include<queue>
#include<vector>
#include<set>
#define LL long long
#define exp 1e-9
#define MAXN 1000010
using namespace std;
int main()
{
// freopen("D:\\in.txt","r",stdin);
int i,l1;
char s1[111]=" ";//注意:这里必须先初始化为一个空格,而不是空字符串!!!
while(gets(s1+1))
{
l1=strlen(s1);
for(i=1;i<=l1;++i)
{
if((s1[i-1]==' '||s1[i-1]=='\t'||s1[i-1]=='\n'||s1[i-1]=='\r')&&s1[i]>='a'&&s1[i]<='z')
{
s1[i]='A'+(s1[i]-'a');
}
}
puts(s1+1);
}
return 0;
}