当前位置: 代码迷 >> 综合 >> 杭电 2026 首字母变大写
  详细解决方案

杭电 2026 首字母变大写

热度:1   发布时间:2023-11-24 14:50:58.0

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2026
Problem Description
输入一个英文句子,将每个单词的第一个字母改成大写字母。

Input
输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。

Output
请输出按照要求改写后的英文句子。

Sample Input
i like acm
i want to get an accepted

Sample Output
I Like Acm
I Want To Get An Accepted

直接上代码:

#include<iostream>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){stringstream sss;string s,ss;while(getline(cin,s)){sss<<s;int first=1;while(sss>>ss){ss[0]=toupper(ss[0]);if(first!=1){cout<<" "<<ss;}else{cout<<ss;first=0;}}cout<<endl;sss.clear();}return 0;
}