//Abhinav Gautam //Barrington High School, Barrington, Rhode Island //Senior Division - 3 /** ASCL Contest #2: "Data Compression" - 2007 - 2008 02/04/08 */ import java.io.*; import java.util.*; import java.lang.*; public class ACSL_2_07_08 { public static void main(String args []) throws IOException { int repeat = 0; while ( repeat != 5 ) { //looping five times for ACSL //inputting System.out.println("Input " + (repeat + 1) + ": "); //input # Scanner in = new Scanner(System.in); ArrayList list = new ArrayList(); String I = in.nextLine(); //input string int w = I.length(); Scanner in2 = new Scanner(I); String a = ""; //temporary string a String b = ""; //temporary string b int cntr = 0; boolean flag = false; while (w > 0) { a = in2.next(); b = ""; for (cntr = 0; cntr < a.length(); cntr++) if (check(a.substring(cntr, cntr + 1)) || ((cntr + 1) < a.length() && check(a.substring(cntr + 1, cntr + 2)))) b += a.substring(cntr, cntr + 1); if (!b.equals("")) list.add(b); w -= (a.length() + 1); } //removes the words that are mentioned once and repeated for (cntr = 0; cntr < list.size(); cntr++) { for (int cntr2 = cntr + 1; cntr2 < list.size(); cntr2++) if (list.get(cntr).equals(list.get(cntr2))) { list.remove(cntr2); flag = true; } if (!flag) { list.remove(cntr); cntr--; } flag = false; } Scanner in3 = new Scanner(I); String O = ""; while (in3.hasNext()) { a = in3.next(); b = ""; for (cntr = 0; cntr < a.length(); cntr++) if (check(a.substring(cntr, cntr + 1)) || ((cntr + 1) < a.length() && check(a.substring(cntr + 1, cntr + 2)))) b += a.substring(cntr, cntr + 1); if (list.contains(b)) O += (list.indexOf(b) + 1); else O += b; if (b.length() != a.length()) O += a.substring(b.length(), a.length()); if(in3.hasNext()) O += " "; } //outputting System.out.println(O); //the answer repeat++; //for the next input } } public static boolean check (String a) { String b[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; for (int c = 0; c < b.length; c++) if (a.equals(b[c])) return true; return false; } } /* (©) Copyright 2008 Abhinav Gautam. All Rights Reserved **/