Minimum palindrome string--New Ket net (Autumn recruit prepares for three die)-c++ direction

Source: Internet
Author: User

Title Description: A string from left-to-right and right-to-left read all the same is a palindrome string, given a string, ask the character in the string can make up the minimum number of palindrome string is how manyproblem-solving ideas: If the number of occurrences of a character is even, it will be able to form a palindrome string, if a character appears odd number of times, can only make a palindrome string, the question of the minimum number of palindrome, that is, to find the number of odd occurrences of the number of characters can be, define a store each character occurrences, Count the number of characters that appear odd number of times, that is, the output
1#include <iostream>2#include <string>3 using namespacestd;4  5 intMain ()6 {7     strings;8Cin>>s;9     intn =s.size ();Ten     intCount =0; One     inta[ the] = {0}; A      for(intI=0; i<n;i++) -     { -a[s[i]]++; the     } -      for(intI=0;i< the; i++) -     { -         if(a[i]%2!=0) +         { -count++; +         } A     } atcout<<count<<Endl; -     return 0; -}

Minimum palindrome string--New Ket net (Autumn recruit prepares for three die)-c++ direction

Related Article

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.