Usaco 1.3.3 calf FLAC (calfflac)

Source: Internet
Author: User

1. Silly brute-force search: The two pointers start from the first and last pointers and move them in the middle to determine whether the string between the two pointers is the number of input packets. Too many repeated searches cause the last test data to time out:

/* <Br/> ID: gengjia1 <br/> LANG: C <br/> task: calfflac <br/> */<br/> # include <stdio. h> <br/> # include <stdlib. h> <br/> # include <string. h> <br/> # include <ctype. h> <br/> // # define ndebug <br/> # include <assert. h> </P> <p> # define max_len 20000 <br/> int count; </P> <p> struct STR {<br/> int Len; <br/> char s [max_len + 1]; <br/>}; </P> <p> struct pal {<br/> int Len; <br/> int begin; <br/> int end; <br/>}; </P> <p> int lett Er (const char a) <br/>{< br/> If (A> = 'A' & A <= 'Z ') | <br/> (A> = 'A' & A <= 'Z') <br/> return 1; <br/> return 0; <br/>}</P> <p> int main (void) {<br/> file * fin = fopen ("calfflac. in "," R "); <br/> file * fout = fopen (" calfflac. out "," W "); <br/> assert (Fin! = NULL & fout! = NULL); </P> <p> struct str s = {0}; <br/> struct pal Pa = {0 }; <br/> char TMP [80] = {0}; <br/> char T [max_len] = {0}; <br/> int curlen = 0; <br/> int I, j, k, p, q; </P> <p> while (fgets (TMP, 80, fin )! = NULL) <br/>{< br/> strcat (S. s, TMP); <br/>}< br/> S. len = strlen (S. s); </P> <p> for (I = 0; I <S. len; I ++) <br/>{< br/> If (letter (S. s [I]) = 0) <br/> continue; <br/> for (j = S. len-1; j> I; j --) <br/>{< br/> If (letter (S. s [J]) = 0) <br/> continue; <br/> curlen = 0; <br/> for (P = I, q = J; P <q;) <br/>{< br/> If (letter (S. s [p]) = 0) <br/>{< br/> P ++; <br/> continue; <br/>}< br/> If (letter (S. s [Q]) = 0) <br/>{< br/> q --; <br/> continue; <br/>}< br/> If (tolower (S. s [p]) = tolower (S. s [Q]) <br/>{< br/> curlen + = 2; <br/> P ++; <br/> q --; <br/>}< br/> else <br/> {<br/> curlen = 0; <br/> break; <br/>}< br/> If (P = Q & letter (S. s [p]) = 1) <br/> curlen + = 1; </P> <p> If (curlen> Pa. len) <br/> {<br/> Pa. len = curlen; <br/> Pa. begin = I; <br/> Pa. end = J; <br/>}< br/> fprintf (fout, "% d/N", Pa. len); <br/> for (I = pa. begin; I <= pa. end; I ++) <br/>{< br/> fprintf (fout, "% C", S. s [I]); <br/>}< br/> fprintf (fout, "/N"); </P> <p> fclose (FIN ); <br/> fclose (fout); <br/> exit (0); <br/>}< br/>

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.