Pages

Friday, December 14, 2007

USACO: Your Ride Is Here

/*
ID: wsoethe1
LANG: JAVA
TASK: ride
*/

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class ride {
public static void main(String[] args) {
final char abc[] = { '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' };
int product = 1;
int planetMod = 0;
boolean check = true;
try {
BufferedReader fileIn = new BufferedReader(
new FileReader("ride.in"));
PrintWriter fileOut = new PrintWriter(new BufferedWriter(
new FileWriter("ride.out")));
try {
String line = "";
while ((line = fileIn.readLine()) != null) {
for (int j = 0; j < line.length(); j++) {
for (int i = 0; i < 26; i++) {
if (line.charAt(j) == abc[i]) {
product *= (i + 1);
break;
}
}
}
if (check) {
planetMod = product % 47;
check = false;
product = 1;
}
}

if (planetMod == (product % 47)) {
fileOut.write("GO\n");
} else {
fileOut.write("STAY\n");
}
} finally {
fileIn.close();
fileOut.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
System.exit(0);
}
}

No comments :