Capitalize the initial letter

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.