Codeforces Educational codeforces Round 2 C make palindrome

Source: Internet
Author: User

C. Make Palindrome

A string is called palindrome if it reads the same from left to right and from right to left. For example "Kazak", "oo", "R" and "Mikhailrubinchikkihcniburliahkim" is palindroms, but strings "AB B "and"ij " is not.

You are given string s consisting of lowercase Latin letters. At once you can choose any position in the string and change letter in that position to any other lowercase letter. So after each changing the length of the string doesn ' t. At first you can change some letters in s. Then you can permute the order of letters as you want. Permutation doesn ' t count as changes.

You should obtain palindrome with the minimal number of changes. If there is several ways to do, you should get the lexicographically (alphabetically) smallest palindrome. So firstly your should minimize the number of changes and then minimize the palindrome lexicographically.

Input

The only line contains string s (1≤|  S| ≤2 105) consisting of only lowercase Latin letters.

Output

Print the lexicographically smallest palindrome that can is obtained with the minimal number of changes.

Sample Test (s) Input
Aabc
Output
Abba
Input
Aabcd
Output
Abcba
1#include <cstdio>2#include <iostream>3#include <vector>4#include <cmath>5#include <queue>6#include <string>7#include <map>8#include <cstring>9#include <algorithm>Ten using namespacestd; OnetypedefLong Longll; Atypedef unsignedLong Longull; - Const intmaxn=2e5+5; - intcnt[ -]; the intMain () - { -     CharS[MAXN]; -     intflag=-1; +scanf"%s", s); -cnt[ -]=0; +     intlen=strlen (s); A      for(intI=0; i<len;i++) cnt[s[i]-'a']++; at      for(intI=0;i< -; i++) -     { -         if(cnt[i]&1) -              for(intj= -; j>i;j--) -                 if(cnt[j]&1) -                 { incnt[i]++; -cnt[j]--; to                      Break; +                 } -     } the      for(intI=0;i< -; i++) *     { $         if(cnt[i]&1) flag=i;Panax Notoginseng          for(intj=0; j<cnt[i]/2; j + +) -printf"%c", i+'a'); the     } +     if(flag>=0) Aprintf"%c", flag+'a'); the      for(intI= -; i>=0; i--) +              for(intj=0; j<cnt[i]/2; j + +) -printf"%c", i+'a'); $Puts""); $     return 0; -}

Codeforces Educational codeforces Round 2 C make palindrome

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.