ArrayList allowed ?? Compile Error

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
kasparov
New poster
Posts: 5
Joined: Wed Oct 20, 2004 7:36 pm

ArrayList allowed ?? Compile Error

Post 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;
}
}
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post 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)
Post Reply

Return to “Java”