import java.util.Arrays; import java.util.Scanner; public class Pro36 { 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); } } } /* Main.java:6: error: class Pro36 is public, should be declared in a file named Pro36.java public class Pro36 { ^ 1 error */ |
Double click to view unformatted code.