Cita de: ghastlyX en 13 Noviembre 2011, 17:13 PM
Te dejo mi solución que pasa los juegos de prueba en USACO:Código (java) [Seleccionar]import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;
public class ride implements Runnable {
PrintWriter writer;
BufferedReader reader;
StringTokenizer tokenizer;
private void solve() throws IOException {
String s = nextToken(), r = nextToken();
int a = 1, b = 1;
for (int i = 0; i < s.length(); ++i) a = (a*(Character.getNumericValue(s.charAt(i)) - 9))%47;
for (int i = 0; i < r.length(); ++i) b = (b*(Character.getNumericValue(r.charAt(i)) - 9))%47;
if (a == b) writer.println("GO");
else writer.println("STAY");
}
public static void main(String[] args) {
new ride().run();
}
public void run() {
try {
reader = new BufferedReader(new FileReader("ride.in"));
writer = new PrintWriter(new FileWriter("ride.out"));
tokenizer = null;
solve();
reader.close();
writer.close();
}
catch (IOException e) {
}
}
String nextToken() throws IOException {
if (tokenizer == null || !tokenizer.hasMoreTokens())
tokenizer = new StringTokenizer(reader.readLine());
return tokenizer.nextToken();
}
}
Ya esta, ya he visto mi fallo se me olvido que no empieza desde 1 sino desde 10 ¬¬.