C++ String programming

Hello, I have come across this problem floating around the wonderful, amazing, and fantabulous internet just waiting for it to be solved. But I cant so can you guys help me?

Background:
String S of length N is entered.

Input:
First line, number of letter of S, which is N.
On the next line, S is entered.

Output

Created in alphabetical order, the fastest output string.

IO Example:
Input
6
ACDBCB

Output
ABCBCD

* Description:
1 - S="ACDBCB", T=""
2 - S="CDBCB", T="A"
3 - S="CDBC", T="AB"
4 - S="CDB", T="ABC"
5 - S="CD", T="ABCB"
6 - S="D", T="ABCBC"
7 - S="", T="ABCBCD"

* Source - USACO Silver
Last edited on
It looks like the algorithm just wants you to peel the next character(s) closest to 'A' off of either end of the algorithm. It also looks optimized to prefer the back end for the convenience of a straight copy of the last n characters, should that be possible (as it is in the given example). It also appears that the algorithm assumes a c-string layout.
Topic archived. No new replies allowed.