View Code of Problem 36

import java.util.ArrayList;
import java.util.Collections;
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();
            ArrayList<String> list = new ArrayList<>();
            for (int k = 0; k < str.length(); k++)
                list.add(String.valueOf(str.charAt(k)));
            Collections.sort(list);
            for (int j = 0; j < list.size(); ) {
                int index = j + 1;
                int count = 1;
                while (index < list.size() && list.get(j).equals(list.get(index))) {
                    count++;
                    index++;
                }
                System.out.print(count + list.get(j));
                j = index;
            }
            System.out.println();
        }
    }
}

Double click to view unformatted code.


Back to problem 36