刷.....
http://acm.hdu.edu.cn/showproblem.php?pid=2026
字母变大写
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13358 Accepted Submission(s): 7358
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>
- using namespace std;
- int main()
- {
- char str[101];
- int i;
- while(cin.getline(str,100))
- {
- cout<<(char)(str[0]-'a'+'A');
- for(i=1;str[i]!='\0';i++)
- {
- if(str[i-1]==' ')
- cout<<(char)(str[i]-'a'+'A');
- else
- cout<<str[i];
- }
- cout<<"\n";
- }
- return 0;
- }
本篇博客介绍了一个简单的程序设计问题:如何将输入的英文句子中每个单词的首字母转换为大写。通过一个具体的示例展示了实现这一功能的C++代码,并提供了输入输出样例。
560

被折叠的 条评论
为什么被折叠?



