//Written by Jay Baffoni // LaSalle Academy, Providence, RI Intermediate Three //Contest two import java.util.Scanner; import java.io.*; public class compression { public static void main(String [] args) throws IOException { Scanner reader = new Scanner(new File("J:\\acsldata#2.txt")); for (int x = 0; x < 5; x++) { System.out.println("\n"); int pos; String input = reader.nextLine() + " "; String word = ""; String words = ""; String punc = ""; String total = ""; for (int i = 0; i < input.length(); i++) { if (input.charAt(i) > 64 && input.charAt(i) < 91 || input.charAt(i) == 32) words += input.substring(i, i+1); else punc += input.substring(i, i+1); } words = " " + words; while (words.length() > 2) { int num = 0; total = words.substring(1, words.length()); int spos = total.indexOf(" "); if (words.length() > 2) word = words.substring(0, spos + 2); while (words.indexOf(word) >= 0 && words.length() > 2) { int position = words.indexOf(word); words = words.substring(0, position) + " " + words.substring(position+word.length(), words.length()); num++; } word = word.substring(1, word.length()-1); System.out.print(num); System.out.print(word); //System.out.println(words); } while (punc.length() > 0) { String mark = ""; int num = 1; if (punc.length() > 0) {mark = punc.substring(0, 1); punc = punc.substring(1, punc.length());} while (punc.indexOf(mark) >= 0 && punc.length() > 0) { int position = punc.indexOf(mark); punc = punc.substring(0, position) + punc.substring(position+1, punc.length()); //System.out.println(punc); num++; } System.out.print(num); System.out.print(mark); } } } }