19:首字母大写
总时间限制: 1000ms 内存限制: 65536kB
描述
对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。在字符串中,单词之间通过空白符分隔,空白符包括:空格(’ ‘)、制表符(’\t’)、回车符(’\r’)、换行符(’\n’)。
输入
输入一行:待处理的字符串(长度小于80)。
输出
输出一行:转换后的字符串。
样例输入
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.
来源
计算概论05
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
char a[100];
int l=0;
while(gets(a)){
l=strlen(a);
if(a[0]>='a'&&a[0]<='z'){
a[0]=a[0]-32;}
cout<<a[0];
for(int i=1;i<l;i++){
if((a[i]==' '||a[i]=='\t'||a[i]=='\n'||a[i]=='\r')&&a[i+1]>='a'&&a[i+1]<='z'){
a[i+1]=a[i+1]-32;}
else
a[i]=a[i];
cout<<a[i];}
}
return 0;
}