hdu 2026 首字母变大写

首字母变大写

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 49003    Accepted Submission(s): 27058

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 <string>
 3 using namespace std;
 4 int main(){
 5     string s;
 6     while(getline(cin, s)){
 7         char c = ' ';
 8         for(int i = 0; i < s.length(); i++){
 9             if(c == ' '){
10                 s[i] = s[i] - 'a' + 'A';
11             }
12             c = s[i];
13         }
14         cout << s << endl;
15     }
16     return 0;
17 }
View Code
 1 #include <iostream>
 2 #include <string>
 3 using namespace std;
 4 int main(){
 5     string s;
 6     while(getline(cin, s)){
 7         for(int i = 0; i < s.length()-1; i++){
 8             if( s[i] == ' ' )
 9                 s[i+1] = s[i+1] - 'a' + 'A';
10             if(i == 0)
11                 s[i] = s[i] - 'a' + 'A';
12         }
13         cout << s << endl;
14     }
15     return 0;
16 }

 

posted @ 2016-06-04 16:39  琴影  阅读(270)  评论(0编辑  收藏  举报