Page 1 of 1

ArrayList allowed ?? Compile Error

Posted: Sat Jul 09, 2005 4:02 pm
by kasparov
I got this compile error :
-------------------------------------------------------------------
03731899_24.java:12: Type `ArrayList' not found in the declaration of the local
variable `ll'.
ArrayList ll;
^
03731899_24.java:68: Type `ArrayList' not found in the declaration of the local
variable `ll'.
ArrayList ll = (ArrayList) m.get(new Integer(str.length()));
-------------------------------------------------------------------
Can't i use the ArrayList or what :-? :-? ?
Here is my code


import java.io.*;
import java.util.*;

class Main
{
static char[] pairs = new char[30];
static Hashtable m = new Hashtable(80);
static String[] Statment;

public static void main(String[] Args) throws IOException
{
ArrayList ll;

// BufferedReader br = new BufferedReader (new FileReader("input.txt"));
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));

// BufferedWriter bw = new BufferedWriter (new FileWriter("output2.txt"));
// BufferedWriter bw = new BufferedWriter (new OutputStreamWriter(System.out));

int x = Integer.parseInt(br.readLine());
// int Max = 0;
for(int i = 0; i < x ; i ++)
{
String str = br.readLine();

ll = (ArrayList) m.get(new Integer(str.length()));
if (ll == null)
ll= new ArrayList();
ll.add(str);

m.put(new Integer(str.length()), ll);
// if (str.length() > Max)
// Max = str.length();
}

String st;

while((st = br.readLine()) != null)
{
for (int i = 'a'; i<='z'; i++)
pairs[i-'a'] = '*';
Statment = st.split(" ");
boolean Done = Solve(0, pairs);
for(int i = 0; i <st.length(); i++)
{
char c = st.toCharArray();
if (c != ' ')
if (Done)
System.out.print(pairs[c-'a']);
else
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
// bw.close();
}

static boolean Done = false;

public static boolean Solve(int n, char[] Pairs)
{
if (n >= Statment.length)
return false;
String str = Statment[n];

ArrayList ll = (ArrayList) m.get(new Integer(str.length()));
char[] TempPairs = new char[30];

for(int i = 0; i<ll.size(); i++)
{
if (IsMatch(str, ll.get(i).toString(), Pairs))
{
for(int j = 0 ; j<30; j++)
TempPairs[j] = Pairs[j];
if(!ApplyChar(str, ll.get(i).toString(), TempPairs))
continue;
if (n == Statment.length - 1)
{
pairs = TempPairs;
return true;
}
if (Solve(n+1, TempPairs))
return true;
}
}
return false;
}

private static boolean ApplyChar(String str, String s, char[] tempPairs)
{
for(int i = 0; i < s.length(); i ++)
{
if (tempPairs[(int)(str.charAt(i) - 'a')] != s.charAt(i) && Exists(s.charAt(i), tempPairs))
return false;
tempPairs[(int)(str.charAt(i) - 'a')] = s.charAt(i);
}
return true;
}

private static boolean Exists(char c, char[] tempPairs)
{
for(int j=0; j<tempPairs.length; j++)
if (tempPairs[j] == c)
return true;
return false;
}

private static boolean IsMatch(String str, String s, char[] p)
{
for(int i = 0; i < s.length(); i ++)
{
if (p[(int)(str.charAt(i)-'a')] != '*' && p[(int)(str.charAt(i)-'a')] != s.charAt(i))
return false;
}
return true;
}
}

Posted: Sun Jul 10, 2005 5:10 am
by chunyi81
Arraylist is not allowed in UVA due to the version of JDK in UVA, which is JDK 1.1 and 1.2(some features only). Also, don't use BufferedReader in your code, you will get restricted function. With regards to BufferedReader, I hope the system administrators can reconsider allowing the use of BufferedReader for reading inputs from standard input (System.in in Java)