Home > Back-end >  The teacher assigned a C language subject is not too will do, ask bosses
The teacher assigned a C language subject is not too will do, ask bosses

Time:12-04

Sixth, thanks for your bosses

CodePudding user response:

 # include & lt; Iostream> 
# include & lt; Boost/tokenizer. Hpp>
#include
Int main ()
{
Int numUpper {0}.
Int numLower {0}.

STD: : string s="the Boost c + + libraries hello 234 World";
Boost: : char_separator & lt; Char> Sep (" ");
Boost: : tokenizer Tok (s, sep);
For (=auto it tok. The begin (); It!=tok. End (); + + it) {
Auto firstChar=(* it) [0].
If (isupper (firstChar))
NumUpper++;
Else if (islower (firstChar))
NumLower++;
}
STD: : cout & lt; <"Number of capitalized words:" & lt; STD: : cout & lt; <"Lowercase word number:" & lt; //number of capitalized words: 3
//lowercase word number: 2
system("pause");
}

CodePudding user response:

reference 1st floor yexian1991 response:
 # include & lt; Iostream> 
# include & lt; Boost/tokenizer. Hpp>
#include
Int main ()
{
Int numUpper {0}.
Int numLower {0}.

STD: : string s="the Boost c + + libraries hello 234 World";
Boost: : char_separator & lt; Char> Sep (" ");
Boost: : tokenizer Tok (s, sep);
For (=auto it tok. The begin (); It!=tok. End (); + + it) {
Auto firstChar=(* it) [0].
If (isupper (firstChar))
NumUpper++;
Else if (islower (firstChar))
NumLower++;
}
STD: : cout & lt; <"Number of capitalized words:" & lt; STD: : cout & lt; <"Lowercase word number:" & lt; //number of capitalized words: 3
//lowercase word number: 2
system("pause");
}

Bosses also is a little bit more simple, we soon started learning C language, the structure also didn't learn

CodePudding user response:

Finite state machine automatically
 
Void main ()
{
//multiple consecutive Spaces as a; Numbers are not inside, "and" symbols such as not as separator
TCHAR * szString=_T (" Hello world aabbc Hehe haha 783279 ABC, ere afdsewre ");
Int state=1;
Int UpperWordsNumb=0;
Int LowerWordsNumb=0;
For (LPCTSTR pStr=szString; * pStr!=_T (' \ 0 '); + + pStr)
{
The switch (state)
{
Case 1:
If (* pStr & gt;=_T (' A ') & amp; & * pStr & lt;=_T (' Z ')
{
+ + UpperWordsNumb;
State=2;
}
Else if (* pStr & gt;=_T (' a ') & amp; & * pStr & lt;=_T (' z '))
{
+ + LowerWordsNumb;
State=2;
}
break;

Case 2:
If (* pStr==_T (') | | * pStr==_T (' \ t ') | | * pStr==_T (' \ r ') | | * pStr==_T (' \ n '))
State=1;
break;
}
}

Printf (_T (" capitalized words count: % d \ r \ n lowercase word number: % d ", UpperWordsNumb, LowerWordsNumb));
}

CodePudding user response:

Just learning C language, the code above is really hard for you, look at this, those who watch above.
 
# include & lt; Stdio. H>
# include & lt; Conio. H>
Int main () {
char ch;//character obtained
Int big=0, small=0;//statistics
Do {
Ch=getchar ();//to get first letter
If (ch & gt;='A' & amp; & Ch & lt;='Z')//whether first letter capitalized
+ + big;
The else
+ + small;
While ((ch=getchar ())!=' '& amp; & Ch!='\ n');//after determine the word first, here to read the rest of the words, until the end of meet Spaces or carriage returns
} while (ch!='\ n');//if not meet enter can continue to read the next word word first
Printf (" the number of word is capitalized words: % d ", big);//statistics and began to output
Printf (" word first is the number of lowercase word: % d ", small);
}

CodePudding user response:

refer to fifth floor white light star reply:
just learning C language, the code above is really hard for you, look at this, those who watch above.
 
# include & lt; Stdio. H>
# include & lt; Conio. H>
Int main () {
char ch;//character obtained
Int big=0, small=0;//statistics
Do {
Ch=getchar ();//to get first letter
If (ch & gt;='A' & amp; & Ch & lt;='Z')//whether first letter capitalized
+ + big;
The else
+ + small;
While ((ch=getchar ())!=' '& amp; & Ch!='\ n');//after determine the word first, here to read the rest of the words, until the end of meet Spaces or carriage returns
} while (ch!='\ n');//if not meet enter can continue to read the next word word first
Printf (" the number of word is capitalized words: % d ", big);//statistics and began to output
Printf (" word first is the number of lowercase word: % d ", small);
}

Thank you very much for bosses
  • Related