This question can be done by using the theory of finite automatic machines. You can also enumerate possible situations and jump to the status after setting various States. For example, if a sentence has ended, this state is set to 0, in the word state is set to 1, and in the middle of the sentence, when the non-word part is set to 2, if it is in the state 0, but encountered a lowercase letter is even an error, in the status of 1, but an uppercase letter is also an error.
# Include <stdio. h> # Include < String . H> # Include <Ctype. h> # Define Maxd 100010 Int N, CNT; Char B [maxd]; Char Isend ( Char Ch ){ Return Ch = ' . ' | CH = ' ? ' | CH = ' ! ' ;} Void Check ( Char Ch, Int & Pat ){ If (PAT = 0 ){ If (Isalpha (CH )){ If (Islower (CH )) ++ CNT; Pat = 1 ;}} Else If (PAT = 1 ){ If (Isalpha (CH )){ If (Isupper (CH )) ++ CNT ;} Else { If (Isend (CH) Pat = 0 ; Else Pat = 2 ;}} Else { If (Isend (CH) Pat = 0 ; Else If (Isalpha (CH) Pat = 1 ;}} Void Solve (){ Int I, pat; CNT =0 , PAT = 0 ; For (I = 0 ; I <n; I ++ ) Check (B [I], Pat );} Int Main () {n = 0 ; While (Scanf ( " % C " , & B [N]) = 1 ) ++ N; solve (); printf ( " % D \ n " , CNT ); Return 0 ;}