杭电 2026 首字母变大写

素颜马尾好姑娘i 2022-05-18 05:20 237阅读 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

直接上代码:

  1. #include<iostream>
  2. #include<cstring>
  3. #include<sstream>
  4. #include<algorithm>
  5. #include<cmath>
  6. using namespace std;
  7. int main(){
  8. stringstream sss;
  9. string s,ss;
  10. while(getline(cin,s)){
  11. sss<<s;
  12. int first=1;
  13. while(sss>>ss){
  14. ss[0]=toupper(ss[0]);
  15. if(first!=1){
  16. cout<<" "<<ss;
  17. }
  18. else{
  19. cout<<ss;
  20. first=0;
  21. }
  22. }
  23. cout<<endl;
  24. sss.clear();
  25. }
  26. return 0;
  27. }

发表评论

表情:
评论列表 (有 0 条评论,237人围观)

还没有评论,来说两句吧...

相关阅读

    相关 SDUTACM字母

    题目描述 输入一个英文句子,将每个单词的第一个字母改成大写字母。 输入 输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。 输出