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