Ural 1038 spell checker

Source: Internet
Author: User

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  ;} 

 

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.