題目描述
對一個字符串中的所有單詞,如果單詞的首字母不是大寫字母,則把單詞的首字母變成大寫字母。 在字符串中,單詞之間通過空白符分隔,空白符包括:空格(' ')、製表符('\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.
C++實現:
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
int main(){
char c[100];
while(gets(c)){
int num=strlen(c);
//注意非字母的特殊處理
if(c[0]>='a'&&c[0]<='z')
cout<<(char)('A'-'a'+c[0]);
else
cout<<c[0];
for(int i=1;i<num;i++){
if((c[i-1]==' '||c[i-1]=='\t'||c[i-1]=='\r'||c[i-1]=='\n')&&c[i]>='a'&&c[i]<='z'){
cout<<(char)('A'-'a'+c[i]);
}
else
cout<<c[i];
}
cout<<endl;
}
}