A. Oh Those Palindromes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
A non-empty string is called palindrome, if it reads the same from the left to the right and from the right to the left. For example, "abcba", "a", and "abba" are palindromes, while "abab" and "xy" are not.
A string is called a substring of another string, if it can be obtained from that string by dropping some (possibly zero) number of characters from the beginning and from the end of it. For example, "abc", "ab", and "c" are substrings of the string "abc", while "ac" and "d" are not.
Let's define a palindromic count of the string as the number of its substrings that are palindromes. For example, the palindromic count of the string "aaa" is 66 because all its substrings are palindromes, and the palindromic count of the string "abc" is 33 because only its substrings of length 11 are palindromes.
You are given a string ss. You can arbitrarily rearrange its characters. You goal is to obtain a string with the maximum possible value of palindromic count.
Input
The first line contains an integer nn (1≤n≤1000001≤n≤100000) — the length of string ss.
The second line contains string ss that consists of exactly nn lowercase characters of Latin alphabet.
Output
Print string tt, which consists of the same set of characters (and each characters appears exactly the same number of times) as string ss. Moreover, tt should have the maximum possible value of palindromic count among all such strings strings.
If there are multiple such strings, print any of them.
Examples
input
Copy
5
oolol
output
Copy
ololo
input
Copy
16
gagadbcgghhchbdf
output
Copy
abccbaghghghgdfd
Note
In the first example, string "ololo" has 99 palindromic substrings: "o", "l", "o", "l", "o", "olo", "lol", "olo", "ololo". Note, that even though some substrings coincide, they are counted as many times as they appear in the resulting string.
In the second example, the palindromic count of string "abccbaghghghgdfd" is 2929.
题意:给一个字符串,让你重新把字符串重新排,使他从左到右把他顺便分成子串,让他可以成回文的子串最多;
思路:当然是按升序排最多回文
SEE:
#include <iostream>
#include <algorithm>
#include <queue>
#include<string.h>
using namespace std;
int main()
{
string s;
int n;
cin>>n>>s;
sort(s.begin(),s.end());
cout<<s<<endl;
return 0;
}