Ultraviolet A 12718 dromicpalin substrings (search for consecutive strings)

Source: Internet
Author: User

Reprinted please indicate the source: http://blog.csdn.net/u012860063

Question link: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 4456

Question: Find the number of return characters in the string. (Note: after changing the letter position in the string, the number of return characters must be included. For example, AAB can be changed: ABA is also a reply ).

Idea: you only need to count the number of occurrences of each letter, and then count the number of occurrences as an odd number. If one or none of the letters with an odd number appear in a string, it meets the question requirements!

The Code is as follows:

# Include <cstdio> # include <cstring> int main () {int T, cont, I, j; char s [1047]; int C [47]; int CAS = 0; while (~ Scanf ("% d", & T) {getchar (); While (t --) {gets (s); int Len = strlen (s); int K = Len; for (I = 0; I <Len; I ++) {cont = 1; memset (C, 0, sizeof (c )); c [s [I]-'a'] ++; For (j = I + 1; j <Len; j ++) {c [s [J]-'a'] ++; If (C [s [J]-'a']) % 2 = 1) cont ++; elsecont --; If (cont = 1 | cont = 0) // one or no K ++;} printf ("case % d: % d \ n ", ++ cas, k) ;}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.