JOI Sort
InterviewTime limit2sMemory limit1024 MB
Given a string of J, O, and I characters, rearrange it so every J precedes every O, and every O precedes every I.
- Level
Easy2 of 10
- Topics
- Sorting, Implementation, String
- Solved
- No attempts yet
Problem
You are given a string S of length N. Each character of S is one of 'J', 'O', or 'I'.
You want to rearrange the characters of S so that the following conditions hold.
- For every pair of a character '
J' and a character 'O', the 'J' comes before the 'O'. - For every pair of a character '
O' and a character 'I', the 'O' comes before the 'I'. - For every pair of a character '
J' and a character 'I', the 'J' comes before the 'I'.
Given a string S, write a program that prints a string obtained by rearranging the characters of S so that the conditions above hold.
Input
The input is given from standard input in the following format.
N
S
Output
Print a string obtained by rearranging the characters of S so that the conditions hold.
Constraints
1 ≦ N ≦ 100.Sis a string of lengthN.- Each character of
Sis one of 'J', 'O', or 'I'.