Link: http://acm.zzuli.edu.cn/problem.php?id=11361136: Initial capitalization time limit: 1 Sec Memory Limit: MB
Submit: 883 Solved: 547
Submitstatusweb Board Description
Enter a sentence that contains only uppercase and lowercase letters and spaces, and change the first letter of each word to uppercase.
Input
Enter an English sentence with a length of not more than 100.
Output
Please output the English sentences that have been rewritten as required.
Sample InputI like ACMSample OutputI like ACMHINT
Sourceidea: Beginning to see this problem, I think very simple, water problem. But when I used strtok, I found the problem, if separated by a space, each word is stored in a string array, the first letter is capitalized, but at this point in the string array the first letter is capitalized, but the relationship between the word and the number of spaces between the word has been scattered. I think if this is the game, I really finished ... It's always too complicated to think about the problem ... Simple functions are accustomed to use, causing some basic steps to write on their own rather laborious. set a variable flag, the start tag is 0, if you encounter a space, flag is marked as 1,continue, if the next word is still a space, flag remains 1,continue, the next word is a letter, if it is lowercase, it will be uppercase or uppercase letters will not change, The flag is then labeled 0, which guarantees the first control of the word, regardless of the other letters except the first letter. Be patient and look at the following code, you should understand:
#include <iostream> #include <string.h> #include <string>using namespace Std;int main () {int lena,i, Flag=0;char A[110];gets (a); Lena=strlen (a); for (i=0;i<lena;i++) { if (a[0]>= ' a ' &&a[0]<= ' Z ') a[i]-=32;else{if (a[i]== ") { flag=1; Continue;} if (flag==1) {if (a[i]>= ' a ' &&a[i]<= ' Z ') {a[i]-=32;} flag=0;}}} Cout<<a<<endl;return 0;}
Capitalize the initial letter