Hdu3294 (find the longest reply string)

Source: Internet
Author: User

# Include <stdio. h>
# Include <string. h>
Char str [200009];
Int main ()
{
Int I, hed, end, e, j, maxlen, len;
Char ch;
While (scanf ("% c % s", & ch, str) = 2)
{
Getchar ();
Maxlen = 0; len = strlen (str); // yes. note this. If a long string cannot be placed in a loop, you must use len. Otherwise, the length of each calculation times out.
For (e = 0; e <len; e ++) // I calculate the str length every time I time out.
{
For (I = 0; e-I> = 0 & 2 * I + 1 <len; I ++) // find the return string with an odd length.
{
If (str [e-I]! = Str [e + I])
Break;
If (2 * I + 1> maxlen)
{
Maxlen = 2 * I + 1; // The length of the input string
Hed = e-I; // start position
End = e + I; // end position
}
}

For (I = 0; e-I> = 0 & 2 * I + 2 <len; I ++) // find the even-length echo string.
{
If (str [e-I]! = Str [e + I + 1])
Break;
If (2 * I + 2> maxlen)
{
Maxlen = 2 * I + 2;
Hed = e-I;
End = e + I + 1;
}
}
}

If (end-hed> = 2)
{
Printf ("% d \ n", hed, end );
For (I = hed; I <= end; I ++) // This saves time and only writes a real retrieval string at a time.
If (ch <= str [I])
Printf ("% c", str [I]-ch + 'A ');
Else
Printf ("% c", 'z'-(ch-str [I]) + 1 );
}
Else
Printf ("No solution! ");

Printf ("\ n ");
}
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.