输入一个英文句子,将每个单词的第一个字母改成大写字母。
输入数据包含多个测试实例,每个测试实例是一个长度不超过100的英文句子,占一行。
请输出按照要求改写后的英文句子。
1 | i like acm |
1 | I Like Acm |
traverse the string to upper the letters.
The point of this problem is to input a string with spaces.
If you use string, you can use
1 | getline(cin, string); |
If you use char array, you can use
1 | cin.getline(str,len); |
Since you don’t know the length, you choose the first one;
And another thing is that to make the letter an uppercase letter, you can just make the character minus 32 which means subtract the ascii code.
eg. 'a' - 32 = 'A'
using stringstream to traverse words.
stringstring can make the sentence sperate by spaces or other special character.
Method 1: traverse letters.
1 |
|
Method 2: traverse words.
1 |
|