您的位置:首页 > 其它

首字母大写

2017-09-15 12:59 162 查看


题目描述

对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。

在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\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 <iostream>
#include <sstream>
#include <vector>
#include <cctype>
using namespace std;

int main(){
string s,buf;
while(getline(cin,s)){
vector<string> msg;
stringstream ss(s);
while(ss>>buf){buf[0]=toupper(buf[0]);msg.push_back(buf);}
int n=msg.size();
for(int i=0;i<n;i++)
if(i<n-1) cout<<msg[i]<<" ";else cout<<msg[i]<<"\n";
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  字符串处理