woonie

ride.java

Aug 16th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. /*
  2. ID: woonie1
  3. LANG: JAVA
  4. PROG: ride
  5. */
  6.  
  7. import java.io.*;
  8. import java.lang.*;
  9. import java.util.*;
  10.  
  11. /**
  12.  * Note that Java console applications need to be run through the java runtime
  13.  * by running "java -jar JarFile.jar" in the command line.
  14.  * Java console applications can not be previewed in the Compilr IDE, only applets can.
  15.  */
  16. class ride {
  17.   public static void main (String [] args) throws IOException {
  18.     // Use BufferedReader rather than RandomAccessFile; it's much faster
  19.     BufferedReader f = new BufferedReader(new FileReader("ride.in"));
  20.                                                   // input file name goes above
  21.     PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("ride.out")));
  22.     // Use StringTokenizer vs. readLine/split -- lots faster
  23.     StringTokenizer s1 = new StringTokenizer(f.readLine());
  24.     StringTokenizer s2 = new StringTokenizer(f.readLine());
  25.                           // Get line, break into tokens
  26.     String str1 = s1.nextToken();  
  27.     String str2 = s2.nextToken();    
  28.     char[] myArray1 = str1.toCharArray();
  29.     char[] myArray2 = str2.toCharArray();
  30.     int length1 = str1.length();
  31.     int length2 = str2.length();
  32.     int[] myArray3 = new int[str1.length()];
  33.     int[] myArray4 = new int[str2.length()];
  34.     for (int i = 0; i<length1; i++){
  35.         myArray3[i] = myArray1[i]-64;
  36.     }
  37.     for (int j = 0; j<length2;j++){
  38.         myArray4[j] = myArray2[j]-64;
  39.     }
  40.     int sum1 = 1;
  41.     int sum2 = 1;
  42.     for (int a = 0; a<length1;a++){
  43.         sum1 *= myArray3[a];
  44.     }
  45.     for (int b= 0; b<length2;b++){
  46.         sum2 *= myArray4[b];
  47.     }
  48.     if ((sum1%47)==(sum2%47)){
  49.         out.println("GO");
  50.     } else{
  51.         out.println("STAY");
  52.     }
  53.            
  54.     out.close();                                  // close the output file
  55.     System.exit(0);                               // don't omit this!
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment