Created
February 23, 2018 21:24
-
-
Save johirbuet/ba4cd0bb44f5ae1213c517ab29b7e73f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Map; | |
import java.util.Scanner; | |
import java.util.TreeMap; | |
public class UVA13088 { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int T = sc.nextInt(); | |
for(int t = 0;t < T;t++) { | |
String s = sc.next(); | |
char [] ca = s.toCharArray(); | |
Map<Character, Integer> map = new TreeMap<>(); | |
char min = 'z'; | |
for(int i =0; i<ca.length;i++) { | |
map.put(ca[i], map.getOrDefault(ca[i], 0) + 1); | |
if(ca[i] < min) { | |
min = ca[i]; | |
} | |
} | |
StringBuffer sf = new StringBuffer(); | |
StringBuffer last = new StringBuffer(); | |
for(Map.Entry<Character, Integer> entry : map.entrySet()) { | |
char c = entry.getKey(); | |
int count = entry.getValue(); | |
for(int i = 0;i< count - 1; i++) { | |
sf.append(min); | |
} | |
last.append(c); | |
} | |
System.out.println(sf.toString() + last.toString()); | |
} | |
sc.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment