I decided to do the USACO training program over the summer. Meanwhile, the darn program has all their solutions/analysis in C++, which I don't do... so I'm posting my solutions here for 1. Just for the heck of it and 2. So other people can tell me what I can do better
import java.util.*;
import java.io.*;
public class ride
{
public static void main(String [] args) throws IOException {
BufferedReader f = new BufferedReader(new FileReader("ride.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("ride.out")));
String comet = f.readLine();
String group = f.readLine();
//I didn't know if java has the ord() or char() function like python does
//and I'm too lazy to find out. Besides, this is easier to understand
String[] list_alpha = {"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"};
ArrayList list = new ArrayList(Arrays.asList(list_alpha));
int comet_num=1;
int group_num=1;
//At the time of submission, I split the loop to two for loops... >.>
//didn't realize that they were same length
for (int x = 0 ; x < comet.length() ; x++)
{
comet_num *= list.indexOf((comet.substring(x, x+1)))+1;
group_num *= list.indexOf((group.substring(x, x+1)))+1;
}
if ((comet_num % 47) == (group_num % 47)){
out.println("GO");
}
else out.println("STAY");
out.close();
System.exit(0);
}
}
-runiteking1
Got comments? Post them below!
No comments:
Post a Comment