import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { String str = sc.next(); char[] chars = str.toCharArray(); Arrays.sort(chars); char a = chars[0]; int count = 1; for (int j = 1; j < chars.length; j++) { if (a == chars[j]) { count++; }else { System.out.print(count); System.out.print(a); a = chars[j]; count = 1; } } System.out.print(count); System.out.print(a); } } } |
Double click to view unformatted code.