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