@@ -0,0 +1,2109 @@
+import java.util.Scanner;%0A%0Apublic class WordCloud %7B%0A    public static final int SPACING_BETWEEN_WORDS = 10;%0A%0A    public static int get_width(String input, int size) %7B%0A        return (int)Math.ceil(9.0/16.0 * input.length() * size);%0A    %7D%0A%0A    public static int get_size(int count, int max_count) %7B%0A        return 8 + (int)Math.ceil(40.0 * (count - 4) / (max_count - 4));%0A    %7D%0A%0A    public static int get_height(String%5B%5D words, int%5B%5D counts, int max_width) %7B%0A        int max_count = 0;%0A        for (int i = 0; i %3C counts.length; i++) %7B%0A            max_count = Math.max(max_count, counts%5Bi%5D);%0A        %7D%0A%0A        int current_width = 0;%0A        int current_height = 0;%0A        int current_max_size = 0;%0A%0A        for (int i = 0; i %3C words.length; i++) %7B%0A            int current_size = get_size(counts%5Bi%5D, max_count);%0A            int width = get_width(words%5Bi%5D, current_size);%0A            current_width += width + SPACING_BETWEEN_WORDS;%0A%0A            if (current_width %3E (max_width + SPACING_BETWEEN_WORDS)) %7B%0A                current_width = width + SPACING_BETWEEN_WORDS;%0A                current_height += current_max_size;%0A                current_max_size = current_size;%0A            %7D else %7B%0A                current_max_size = Math.max(current_size, current_max_size);%0A            %7D%0A        %7D%0A        return current_height + current_max_size;%0A    %7D%0A%0A    public static void main( String%5B%5D args ) %7B%0A        Scanner stdin = new Scanner(System.in);%0A        int cloud_number = 0;%0A        while (++cloud_number %3E 0) %7B%0A            int max_width = stdin.nextInt();%0A            int word_count = stdin.nextInt();%0A            if (max_width == 0 && word_count == 0) %7B%0A                break;%0A            %7D%0A%0A            String%5B%5D words = new String%5Bword_count%5D;%0A            int%5B%5D counts = new int%5Bword_count%5D;%0A            for (int i = 0; i %3C word_count; i++) %7B%0A                words%5Bi%5D = stdin.next();%0A                counts%5Bi%5D = stdin.nextInt();%0A            %7D%0A%0A            System.out.print(%22CLOUD %22 + String.valueOf(cloud_number) + %22: %22);%0A            System.out.println(get_height(words, counts, max_width));%0A        %7D%0A    %7D%0A%7D%0A

Add WordCloud solution