What's wrong with this submission?

Write here if you have problems with your Java source code

Moderator: Board moderators

Post Reply
project_00
New poster
Posts: 2
Joined: Thu Jun 19, 2003 9:28 am

What's wrong with this submission?

Post by project_00 » Thu Jun 19, 2003 10:30 am

[java]import java.io.*;
import java.lang.Math;
import java.util.*;

class Main{
//public commented out for use in OJ submission


static void main (String args[]) // entry point from OS
{
Main myWork = new Main(); // create a dinamic instance
myWork.Begin(); // the true entry point
}

void Begin(){
StringTokenizer strtok;
String inLine;
while ((inLine=Main.readLine(256))!=null){
strtok=new StringTokenizer(inLine);
long [] origBin= putOrigBin(strtok);
long minMoves=(long)Math.pow(2, 31);
StringBuffer sbuf = new StringBuffer("BGC");
long total=0;
for (int i=0; i<origBin.length; i++)
total +=origBin;
Vector bin1=new Vector(), bin2 =new Vector(), bin3=new Vector();


StringBuffer buffer=new StringBuffer("");

for (int i=0; i<6; i++){
for (int j=0; j<3; j++) bin1.add(""+origBin[j]);
for (int j=3; j<6; j++) bin2.add(""+origBin[j]);
for (int j=6; j<9; j++) bin3.add(""+origBin[j]);
Vector [] VectArray = {bin1, bin2, bin3};
sbuf = new StringBuffer("BGC");

long moves = findMoves(VectArray,total, i);

if (minMoves>moves){
buffer = Arrange(sbuf, i);
minMoves =moves;
}//end if minMoves > moves
else if (minMoves==moves){
StringBuffer temp = buffer;
buffer = Arrange(sbuf, i);

if ((temp.toString().compareTo(buffer.toString())<0))
buffer = temp;


}
}//end for all combinations
System.out.println(buffer+" "+minMoves);
}//end inLine while
}//end begin

static String readLine (int maxLength)
{
byte line[] = new byte [maxLength];
int length = 0, input = -1;

try
{
while (length < maxLength)
{
input = System.in.read();
if ((input < 0) || (input == '\n'))
break;
line [length++] += input;
}
}
catch (IOException ex)
{
return null;
}

if ((input < 0) && (length == 0))
return null;
return (new String (line, 0, length));
}

static long [] putOrigBin(StringTokenizer strtok){
long [] bin = new long [9];
for (int i=0; i<9; i++)
bin=(Long.valueOf(strtok.nextToken())).longValue();
return bin;
} //end putOrigBin()


static long findMoves(Vector [] VA, long total, int num){
long sum=0;
int run = VA[0].size();
int divisor=VA.length-1;
for (int i=0; i<run; i++){
int index=num/divisor;
sum +=(Long.valueOf((String)VA.elementAt(index))).longValue();
for (int j=0; j<VA.length; j++)
VA[j].remove(index);

if (divisor>1)
num %= divisor--;

else num=0;
}

return total-sum;
}

static StringBuffer Arrange(StringBuffer sbuf, int num){
int run = sbuf.length();
StringBuffer buff= new StringBuffer("");
int divisor = sbuf.length()-1;
for (int i=0; i<run; i++){

int index=num/divisor;
buff.append(sbuf.charAt(index));
sbuf.deleteCharAt(index);

if (divisor>1)
num%=divisor--;
else num=0;
}

return buff;
}

}[/java]

I keep getting compile error despite it working ok on jdk 1.4.1
Does anyone know where's the problem?
Am I using a disallowed class? I'm using vectors, stringbuffers and stringtokenizer.

Thanks.

xbeanx
Experienced poster
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Post by xbeanx » Fri Aug 08, 2003 10:47 pm

AFAIK, vectors are a no no.

I had to program my own Stack, ArrayList, and (I believe) Vector class in past problems.

Post Reply

Return to “Java”